Bonjour,
J'ai créé une Librairy qui contient des resources. J'aimerai, à la génération de la dll, créé dynamiquement un Enum contenant les keys présentes dans mes resources.
J'ai trouver comment faire sur la MSDN : http://msdn.microsoft.com/en-us/libr...umbuilder.aspx
L'inconvénient, c'est qu'il n'y a pas de : Main dans une Librairy.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 public static void Main() { // 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)); } }
Merci d'avance.
Partager