TypeBuilder Problems in My Compiler.
-
I am writing a compiler using C# and the System.Reflection.Emit classes. The problem I am having is that I go through and create my classes for my language using TypeBuilder but I can't use those classes until I call CreateType. This wouldn't be a problem except that I potentially have to define instances of the class within the class (and therefore before I call CreateType). An example of this would be a linked list node that contains an instance of itself as the next node. So the real question is if there is some way to get the System.Type of a TypeBuilder before calling CreateType. Or alternately, is there some way to add functions and variables to an already created type that I still have the TypeBuilder for but have called CreateType? I need this because many things need a System.Type and I need to allow users to use the classes they create while programming. Thanks
-
I am writing a compiler using C# and the System.Reflection.Emit classes. The problem I am having is that I go through and create my classes for my language using TypeBuilder but I can't use those classes until I call CreateType. This wouldn't be a problem except that I potentially have to define instances of the class within the class (and therefore before I call CreateType). An example of this would be a linked list node that contains an instance of itself as the next node. So the real question is if there is some way to get the System.Type of a TypeBuilder before calling CreateType. Or alternately, is there some way to add functions and variables to an already created type that I still have the TypeBuilder for but have called CreateType? I need this because many things need a System.Type and I need to allow users to use the classes they create while programming. Thanks
I feel your pain. I abandoned IL , and went with codedom. :) , but I believe inheritance will solve your problem here. :)
-
I am writing a compiler using C# and the System.Reflection.Emit classes. The problem I am having is that I go through and create my classes for my language using TypeBuilder but I can't use those classes until I call CreateType. This wouldn't be a problem except that I potentially have to define instances of the class within the class (and therefore before I call CreateType). An example of this would be a linked list node that contains an instance of itself as the next node. So the real question is if there is some way to get the System.Type of a TypeBuilder before calling CreateType. Or alternately, is there some way to add functions and variables to an already created type that I still have the TypeBuilder for but have called CreateType? I need this because many things need a System.Type and I need to allow users to use the classes they create while programming. Thanks
Hmm, TypeBuilder itself is derrived from Type, perhaps that's what you need. I also see the following remark in the documentation for TypeBuilder: To retrieve a Type object for an incomplete type, use ModuleBuilder.GetType with a string representing the type name, such as "MyType" or "MyType[]". Burt Harris