Enumerating built-in and custom Types available

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm building an application generator and within it a user can create a new
property (for the class they are building). I'd like then to offer a list of
Types - built-in and custom - for this new property to be shown in a combo
box ie similar to Intellisense.

How do you enumerate the Types available? Are their mechanisms for filtering
the list to show only (say) primitive types or custom types or reference
types?

TIA

Crispin
 
CrispinH said:
I'm building an application generator and within it a user can create a
new
property (for the class they are building). I'd like then to offer a list
of
Types - built-in and custom - for this new property to be shown in a combo
box ie similar to Intellisense.

How do you enumerate the Types available? Are their mechanisms for
filtering
the list to show only (say) primitive types or custom types or reference
types?

At runtime: 'System.Reflection', 'Assembly.GetTypes', 'Type' class, ...
 
Herfried K. Wagner said:
At runtime: 'System.Reflection', 'Assembly.GetTypes', 'Type' class, ...

Assembly.GetExportedTypes() will perform better, since you are interested
normally in public types...

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
Herfried

Thanks for that. Reflection was the clue I needed, but I'm not completely
where I want to be. Since I'm effectively trying to emulate VB.NET:

Dim objObject As ...

where the ... is the IntelliSense drop-down box. Thus far I've created test
code:

Dim objSystemObjectAssembly As [Assembly] =
[Assembly].GetAssembly(GetType(System.Object))
Dim objTypes() As Type = objSystemObjectAssembly.GetTypes

I chose the System.Object which returns 1480 items, many of which are not
relevant, so I filtered out those that weren't 'Public'.

However in a Visual Studio project, one puts in references eg:

System
System.Data
System.Drawing
System.Windows.Forms
System.XML

and this extends the Types available. I'd like to do a similar thing for my
users. I could pick an object at random in (say) System.Data and replace
System.Object in the above code, but this doesn't seem very elegant. Is
there a better way of achieving this?

Regards

Crispin
 
Carlos

I tried GetExportedTypes instead of GetTypes and the count on the System
Object fell from 1480 to 905 which is a benefit. Filtering to include only
Public types brings it to 174 again (same for both).

I think I may to to implement some kind of Frequently Used Types system.

Thanks for your help.


Crispin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top