本文整理汇总了C#中System.Reflection.Emit.ModuleBuilder.DefineResource方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleBuilder.DefineResource方法的具体用法?C# ModuleBuilder.DefineResource怎么用?C# ModuleBuilder.DefineResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.ModuleBuilder
的用法示例。
在下文中一共展示了ModuleBuilder.DefineResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodeGenerator
//引入命名空间
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
public class CodeGenerator
{
public CodeGenerator()
{
// Get the current application domain for the current thread.
AppDomain currentDomain = AppDomain.CurrentDomain;
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "TempAssembly";
// Define 'TempAssembly' assembly in the current application domain.
AssemblyBuilder myAssemblyBuilder =
currentDomain.DefineDynamicAssembly
(myAssemblyName, AssemblyBuilderAccess.RunAndSave);
// Define 'TempModule' module in 'TempAssembly' assembly.
ModuleBuilder myModuleBuilder =
myAssemblyBuilder.DefineDynamicModule("TempModule",
"TempModule.netmodule",true);
// Define the managed embedded resource, 'MyResource' in 'TempModule'.
IResourceWriter myResourceWriter =
myModuleBuilder.DefineResource("MyResource.resource","Description");
// Add resources to the resource writer.
myResourceWriter.AddResource("String 1", "First String");
myResourceWriter.AddResource("String 2", "Second String");
myResourceWriter.AddResource("String 3", "Third String");
myAssemblyBuilder.Save("MyAssembly.dll");
}
}
public class CallerClass
{
public static void Main()
{
CodeGenerator myGenerator = new CodeGenerator();
Console.WriteLine("A resource named 'MyResource.resource'"
+" has been created and can be viewed in the 'MyAssembly.dll'");
}
}
示例2: CodeGenerator
//引入命名空间
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
public class CodeGenerator
{
public CodeGenerator()
{
// Get the current application domain for the current thread.
AppDomain currentDomain = AppDomain.CurrentDomain;
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "TempAssembly";
// Define 'TempAssembly' assembly in the current application domain.
AssemblyBuilder myAssemblyBuilder =
currentDomain.DefineDynamicAssembly
(myAssemblyName, AssemblyBuilderAccess.RunAndSave);
// Define 'TempModule' module in 'TempAssembly' assembly.
ModuleBuilder myModuleBuilder =
myAssemblyBuilder.DefineDynamicModule("TempModule",
"TempModule.netmodule",true);
// Define the managed embedded resource, 'MyResource' in 'TempModule'
// with the specified attribute.
IResourceWriter writer =
myModuleBuilder.DefineResource("MyResource.resource",
"Description",ResourceAttributes.Public);
// Add resources to the resource writer.
writer.AddResource("String 1", "First String");
writer.AddResource("String 2", "Second String");
writer.AddResource("String 3", "Third String");
myAssemblyBuilder.Save("MyAssembly.dll");
}
}
public class CallerClass
{
public static void Main()
{
CodeGenerator myGenerator = new CodeGenerator();
Console.WriteLine("A resource named 'MyResource.resource'"
+" has been created and can be viewed in the 'MyAssembly.dll'");
}
}