I am working on a library project. I will distribute this library dll to some other projects for reference. My aim is to generate enum for each time , when ever the project(client project which referenced my dll) build.
I would like create Enum types based on values from api fetch at build time. I am working on .net standard library (2.0) . Requirement is to create a Enum at compile time based on a values, which i will fetch from api call. I tried the following code
// 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 name = new AssemblyName("MyEnums");
AssemblyBuilder assemblyBuilder = currentDomain.DefineDynamicAssembly(name,
AssemblyBuilderAccess.RunAndSave);
// Define a dynamic module in "MyEnums" assembly.
// For a single-module assembly, the module has the same name as the assembly.
ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(name.Name,
name.Name + ".dll");
// Define a public enumeration with the name "MyEnum" and an underlying type of Integer.
EnumBuilder myEnum = moduleBuilder.DefineEnum("EnumeratedTypes.MyEnum",
TypeAttributes.Public, typeof(int));
but "DefineDynamicAssembly" is not available.
Can anybody guide me to do this. Thanks in advance.