本文整理汇总了C#中System.Reflection.Emit.ModuleBuilder.DefineManifestResource方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleBuilder.DefineManifestResource方法的具体用法?C# ModuleBuilder.DefineManifestResource怎么用?C# ModuleBuilder.DefineManifestResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.ModuleBuilder
的用法示例。
在下文中一共展示了ModuleBuilder.DefineManifestResource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IncludeDLL
public static Assembly IncludeDLL(ModuleBuilder ASM, string Filen, string DestDir = null)
{
DestDir = DestDir ?? Directory.GetCurrentDirectory();
var fstream = File.OpenRead(Filen);
ASM.DefineManifestResource(Path.GetFileName(Filen), fstream, ResourceAttributes.Public);
//r.Generate();
return Assembly.LoadFrom(Filen);
}
示例2: GenerateAssemblyLookup
private void GenerateAssemblyLookup(ModuleBuilder module)
{
if (_embeddedAssemblies.Count == 0) {
return;
}
foreach (Assembly ass in _embeddedAssemblies) {
string shortname = ass.FullName.Substring(0, ass.FullName.IndexOf(","));
string tempfile = Path.GetTempFileName();
File.Copy(new Uri(ass.EscapedCodeBase).LocalPath, tempfile, true);
MemoryStream ms = new MemoryStream(File.ReadAllBytes(tempfile));
ms.Seek(0, SeekOrigin.Begin);
module.DefineManifestResource(shortname, ms, ResourceAttributes.Public);
File.Delete(tempfile);
}
MethodBuilder resolveAssemblyMethod = module.DefineGlobalMethod("ResolveAssembly", MethodAttributes.Public | MethodAttributes.Static, typeof(Assembly), new Type[] { typeof(object), typeof(System.ResolveEventArgs) });
ILGenerator ilResolve = resolveAssemblyMethod.GetILGenerator();
CompileContext resolvecontext = new CompileContext();
resolvecontext.PushIL(ilResolve);
LocalBuilder localStream = ilResolve.DeclareLocal(typeof(Stream));
LocalBuilder localBuf = ilResolve.DeclareLocal(typeof(byte[]));
LocalBuilder localName = ilResolve.DeclareLocal(typeof(string));
ilResolve.Emit(OpCodes.Ldarg_1);
ilResolve.Emit(OpCodes.Call, typeof(ResolveEventArgs).GetMethod("get_Name"));
ilResolve.Emit(OpCodes.Stloc, localName);
ilResolve.Emit(OpCodes.Ldloc, localName);
ilResolve.Emit(OpCodes.Ldc_I4_0);
ilResolve.Emit(OpCodes.Ldloc, localName);
ilResolve.Emit(OpCodes.Ldstr, ",");
ilResolve.Emit(OpCodes.Call, typeof(string).GetMethod("IndexOf", new Type[] { typeof(string) }));
ilResolve.Emit(OpCodes.Call, typeof(string).GetMethod("Substring", new Type[] { typeof(int), typeof(int) }));
ilResolve.Emit(OpCodes.Stloc, localName);
Assign(localStream, Call(Call(typeof(Assembly), "GetExecutingAssembly", false), "GetManifestResourceStream", false, localName), resolvecontext);
Label notNull = ilResolve.DefineLabel();
ilResolve.Emit(OpCodes.Ldloc, localStream);
ilResolve.Emit(OpCodes.Brtrue, notNull);
{
//Not found, just return null
ilResolve.Emit(OpCodes.Ldnull);
ilResolve.Emit(OpCodes.Ret);
}
ilResolve.MarkLabel(notNull);
Call(localStream, "get_Length", false).Compile(resolvecontext);
ilResolve.Emit(OpCodes.Conv_Ovf_I);
ilResolve.Emit(OpCodes.Newarr, typeof(System.Byte));
ilResolve.Emit(OpCodes.Stloc, localBuf);
ilResolve.Emit(OpCodes.Ldloc, localStream);
ilResolve.Emit(OpCodes.Ldloc, localBuf);
ilResolve.Emit(OpCodes.Ldc_I4_0);
ilResolve.Emit(OpCodes.Ldloc, localBuf);
ilResolve.Emit(OpCodes.Ldlen);
ilResolve.Emit(OpCodes.Conv_I4);
ilResolve.Emit(OpCodes.Callvirt, typeof(Stream).GetMethod("Read", new Type[] { typeof(byte[]), typeof(int), typeof(int) }));
ilResolve.Emit(OpCodes.Pop);
//Notify that we loaded this embedded...
ilResolve.Emit(OpCodes.Ldarg_1);
ilResolve.Emit(OpCodes.Call, typeof(ResolveEventArgs).GetMethod("get_Name"));
ilResolve.Emit(OpCodes.Ldstr, " was not found externally, loading embedded version...");
ilResolve.Emit(OpCodes.Call, typeof(string).GetMethod("Concat", new Type[] { typeof(string), typeof(string) }));
ilResolve.Emit(OpCodes.Call, typeof(System.Console).GetMethod("WriteLine", new Type[] { typeof(string) }));
Call(typeof(Assembly), "Load", false, localBuf).Compile(resolvecontext);
ilResolve.Emit(OpCodes.Ret);
resolvecontext.PopIL();
MethodBuilder moduleInitializer = module.DefineGlobalMethod(".cctor", MethodAttributes.Private | MethodAttributes.Static | MethodAttributes.RTSpecialName, null, new Type[] { });
ILGenerator ilStartup = moduleInitializer.GetILGenerator();
ilStartup.Emit(OpCodes.Call, typeof(System.AppDomain).GetMethod("get_CurrentDomain"));
ilStartup.Emit(OpCodes.Ldnull);
ilStartup.Emit(OpCodes.Ldftn, resolveAssemblyMethod);
ilStartup.Emit(OpCodes.Newobj, MethodResolver.GetConstructor(typeof(System.ResolveEventHandler)));
ilStartup.Emit(OpCodes.Callvirt, MethodResolver.GetMethod(typeof(System.AppDomain), "add_AssemblyResolve"));
ilStartup.Emit(OpCodes.Ret);
}
示例3: AddFile
private void AddFile(ModuleBuilder moduleBuilder, FileInfo filePath, FileStream file, List<FileStream> files)
{
moduleBuilder.DefineManifestResource(filePath.Name, file, ResourceAttributes.Public);
files.Add(file);
}
示例4: AddResource
/// <summary>
/// Embeds a single resource into the assembly.
/// </summary>
void AddResource(ModuleBuilder moduleBuilder, ResourceFile resourceFile)
{
string fileName = resourceFile.FileName;
string extension = Path.GetExtension(fileName).ToLowerInvariant();
if (extension == ".resources") {
string fullFileName = Path.GetFileName(fileName);
IResourceWriter resourceWriter = moduleBuilder.DefineResource(fullFileName, resourceFile.Name, ResourceAttributes.Public);
AddResources(resourceWriter, fileName);
} else {
moduleBuilder.DefineManifestResource(resourceFile.Name, new FileStream(fileName, FileMode.Open), ResourceAttributes.Public);
}
}
示例5: AddRpsAddinXmlToAssembly
private void AddRpsAddinXmlToAssembly(string addinName, XDocument doc, ModuleBuilder moduleBuilder)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(doc.ToString());
writer.Flush();
stream.Position = 0;
moduleBuilder.DefineManifestResource(addinName + ".xml", stream, ResourceAttributes.Public);
}