Hello everyone,
I am actually trying to create or generate automatically struct using the class "TypeBuilder".
I have already found a solution to create an "enum".
Here is the Code that I found as example on the microsoft-page:
- using System.Reflection;
- using System.Reflection.Emit;
-
- namespace testnamespace
- {
- class test
- {
- public void CreateEnum()
- {
-
- AppDomain currentDomain = AppDomain.CurrentDomain;
-
-
-
- AssemblyName aName = new AssemblyName("TempAssembly");
- AssemblyBuilder ab = currentDomain.DefineDynamicAssembly(
- aName, AssemblyBuilderAccess.RunAndSave);
-
-
-
- ModuleBuilder mb = ab.DefineDynamicModule(aName.Name, aName.Name + ".dll");
-
-
-
- EnumBuilder eb = mb.DefineEnum("Elevation", TypeAttributes.Public, typeof(int));
-
-
- eb.DefineLiteral("Low", 0);
- eb.DefineLiteral("High", 1);
-
-
- Type finished = eb.CreateType();
- ab.Save(aName.Name + ".dll");
- foreach(object o in Enum.GetValues(finished) )
- {
- Console.WriteLine("{0}.{1} = {2}", finished, o, ((int) o));
- }
- }
How can I do the same procedure to get a struct (NOT A CLASS ;) )
Thank you.