"Best" method to look up for a type by full name

Topics: Metadata Model
Dec 3, 2010 at 12:36 PM
Edited Dec 3, 2010 at 12:39 PM

Hello.

You have the full name of a type (either in "dotted notation" or as array of namespace name and a plain type name) and have to find the corresponding type reference(s)/definition(s) in a set of assemblies.

What's the best way to do it?

1) Get the full dotted name of each type in each assembly with TypeHelper.GetTypeName() and collect the matching types?

2) walk the namespace and type hiearchy of each assembly and collect the leaves that are reached?

Thanks.

Dec 3, 2010 at 5:55 PM

To answer myself: number 2 is faster when working with many types.

 

Coordinator
Dec 3, 2010 at 6:06 PM

My recommendation is to use option 2. And if you intern the various names before doing the traversal, the performance difference can be enormous.

Dec 27, 2010 at 7:36 PM

UnitHelper.FindType() method