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()
- {
- // Get the current application domain for the current thread.
- AppDomain currentDomain = AppDomain.CurrentDomain;
- // Create a dynamic assembly in the current application domain,
- // and allow it to be executed and saved to disk.
- AssemblyName aName = new AssemblyName("TempAssembly");
- AssemblyBuilder ab = currentDomain.DefineDynamicAssembly(
- aName, AssemblyBuilderAccess.RunAndSave);
- // Define a dynamic module in "TempAssembly" assembly. For a single-
- // module assembly, the module has the same name as the assembly.
- ModuleBuilder mb = ab.DefineDynamicModule(aName.Name, aName.Name + ".dll");
- // Define a public enumeration with the name "Elevation" and an
- // underlying type of Integer.
- EnumBuilder eb = mb.DefineEnum("Elevation", TypeAttributes.Public, typeof(int));
- // Define two members, "High" and "Low".
- eb.DefineLiteral("Low", 0);
- eb.DefineLiteral("High", 1);
- // Create the type and save the assembly.
- 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.
Mageshwaran RPosted Nov 23, 2019, 12:31 PM
matt GommPosted Aug 7, 2019, 8:25 AM
matt GommPosted Jul 30, 2019, 4:45 AM
Jaish MathewsPosted Jul 30, 2019, 3:59 AM