I'm building a .NET assembly loader in C# for an "experiment"/learning more about .NET internal operations. I've implemented the reflection API by deriving types like:
- RuntimeType : Type
- RuntimeFieldInfo : FieldInfo
- RuntimeMethodInfo : MethodInfo
- RuntimeParameterInfo : ParameterInfo
- RuntimeConstructorInfo : ConstructorInfo
- RuntimePropertyInfo : PropertyInfo
Unfortunately I'm having trouble because the following have no publicly accessible constructors, so I can't derive from them:
- Assembly (not sealed - AssemblyBuilder is internally derived from it)
- Module (not sealed - ModuleBuilder is internally derived from it)
I need something to return from RuntimeType.get_Assembly
and RuntimeType.get_Module
. Suggestions? Get creative - I've had to. ;) For creating RuntimeTypeHandle
instances, some unsafe casting of pointers gets the job done, but it's not so easy here.
As an aside: The particular trouble now is I'm trying to pretty-print the IL for the loaded types. For constructed generics, the Type.FullName
property includes the generic parameters via the AssemblyQualifiedName
property, which in turn relies on the Assembly
property.