This project is read-only.

Classes missing from SystemCoreAssemblySymbolicIdentity's ExportedTypes?

Topics: Metadata Model
Jun 6, 2011 at 9:21 PM

I'm trying to get references to the various Func and Action classes, which are in System.Core and mscorlib (according to Visual Studio's Object Browser). Using the default host, I've tried:

var sysCoreAssembly = host.LoadAssembly(host.SystemCoreAssemblySymbolicIdentity);

foreach (var type in sysCoreAssembly.ExportedTypes) {
    // if name is "Action" or "Func", do something...
}

However, this only gives back 5 Func classes and 4 Action classes on my system, when there should be 16 of each (corresponding to the number of arguments each accepts). How can I find the others?

I've also tried loading mscorlib directly using host.LoadUnitFrom and then iterating over its ExportedTypes, ExportedTypes was empty (which seems odd in itself).

Thanks,

Brendan

Jun 6, 2011 at 9:33 PM

ExportedTypes does not do what you want. See the documentation:

/// Public types defined in other modules making up this assembly and to which other assemblies may refer to via this assembly.

IEnumerable<IAliasForType> ExportedTypes { get; }

To find the types defined in an assembly use the GetAllTypes method:

Returns all of the types defined in the current module. These are always named types, in other words: INamespaceTypeDefinition or INestedTypeDefinition instances.

IEnumerable<INamedTypeDefinition> GetAllTypes();

Given a type, you can see if it is "exported" by checking if it is visible outside the assembly, using TypeHelper.IsVisibleOutsideAssembly

Decides if the given type definition is visible to assemblies other than the assembly it is defined in (and other than its friends).

public static bool IsVisibleOutsideAssembly(ITypeDefinition typeDefinition)

 

 

Jun 6, 2011 at 9:54 PM

Thanks! I was indeed misinterpreting the meaning of ExportedTypes. I see all the classes I was missing now.