本文整理汇总了C#中System.Reflection.Emit.Label.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# Label.Initialize方法的具体用法?C# Label.Initialize怎么用?C# Label.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.Label
的用法示例。
在下文中一共展示了Label.Initialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
public void Generate()
{
var asName = new AssemblyName(config.TargetAssemblyName)
{
Version = new Version(config.Version),
ProcessorArchitecture = ProcessorArchitecture.MSIL,
};
var aBldr = AppDomain.CurrentDomain.DefineDynamicAssembly(asName, AssemblyBuilderAccess.Save);
aBldr.SetCustomAttribute(new CustomAttributeBuilder(typeof(CompilationRelaxationsAttribute).GetConstructor(new Type[] { typeof(int) }), new object[] { (int)CompilationRelaxations.NoStringInterning }));
aBldr.SetCustomAttribute(new CustomAttributeBuilder(typeof(AssemblyVersionAttribute).GetConstructor(new Type[] { typeof(string) }), new object[] { config.Version }));
aBldr.SetCustomAttribute(new CustomAttributeBuilder(typeof(AssemblyFileVersionAttribute).GetConstructor(new Type[] { typeof(string) }), new object[] { config.Version }));
#if DEBUG
var modBldr = aBldr.DefineDynamicModule(config.TargetAssemblyName, config.TargetAssemblyName + ".dll", true);
#else
var modBldr = aBldr.DefineDynamicModule(config.TargetAssemblyName, config.TargetAssemblyName + ".dll");
#endif
#region Generate Archive Type
var asmTpBldr = modBldr.DefineType(config.TargetNamespace + ".CustomArchive", TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Sealed, typeof(Archive));
ConstructorBuilder archiveConstructor = null;
{
var tree = FileTreeDescriptor.GetTree(config);
FieldBuilder initCompressionData = null;
FieldBuilder allCompressionField = null;
byte[] usedCompressionAlgorithms = null;
{
var dat = tree.GetCompressionData();
if (dat.Where(b => b != 0).Count() > 0)
{
usedCompressionAlgorithms = tree.GetUsedCompressionAlgorithms();
initCompressionData = asmTpBldr.DefineInitializedData("InitData_Compression", dat, FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
allCompressionField = asmTpBldr.DefineField("AllCompressions", typeof(byte[]), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
}
}
var initInternalLengthData = asmTpBldr.DefineInitializedData("InitData_InternalLength", tree.GetInternalLengthData(), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
var allInternalLengthsField = asmTpBldr.DefineField("AllInternalLengths", typeof(int[]), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
var initLengthData = asmTpBldr.DefineInitializedData("InitData_Length", tree.GetLengthData(), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
var allLengthsField = asmTpBldr.DefineField("AllLengths", typeof(int[]), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
var initOffsetData = asmTpBldr.DefineInitializedData("InitData_Offset", tree.GetOffsetData(), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
var allOffsetsField = asmTpBldr.DefineField("AllOffsets", typeof(long[]), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
byte[] dirsData = tree.GetDirectoriesData();
var initDirectoriesData = asmTpBldr.DefineInitializedData("InitData_Directories", dirsData, FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
var allDirectoriesField = asmTpBldr.DefineField("AllDirectories", typeof(string[]), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
byte[] filesData = tree.GetFilesData();
var initFilesData = asmTpBldr.DefineInitializedData("InitData_Files", filesData, FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
var allFilesField = asmTpBldr.DefineField("AllFiles", typeof(string[]), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
var fileSwitchDictionaryField = asmTpBldr.DefineField("FileSwitchDictionary", typeof(Dictionary<string, int>), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
fileSwitchDictionaryField.SetCustomAttribute(GetCompilerGeneratedAttribute());
var fileField = asmTpBldr.DefineField("file", typeof(FileStream), FieldAttributes.Private);
{
archiveConstructor = asmTpBldr.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { typeof(ArchiveFactory), typeof(string) });
const int P_factory = 1;
archiveConstructor.DefineParameter(P_factory, ParameterAttributes.None, "factory");
const int P_fileName = 2;
archiveConstructor.DefineParameter(P_fileName, ParameterAttributes.None, "fileName");
var gen = archiveConstructor.GetILGenerator();
gen.LoadThis();
gen.LoadParameter(P_factory);
gen.LoadParameter(P_fileName);
gen.Emit(OpCodes.Call, typeof(Archive).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(ArchiveFactory), typeof(string) }, new ParameterModifier[] { }));
gen.LoadThis();
gen.LoadParameter(P_fileName);
gen.Emit(OpCodes.Ldc_I4_3); // FileMode.Open
gen.Emit(OpCodes.Ldc_I4_1); // FileAccess.Read
gen.Emit(OpCodes.Newobj, typeof(FileStream).GetConstructor(new Type[] { typeof(string), typeof(FileMode), typeof(FileAccess) }));
gen.Emit(OpCodes.Stfld, fileField);
gen.Emit(OpCodes.Ret);
}
{
var mBldr = asmTpBldr.DefineMethod("Dispose", MethodAttributes.Public | MethodAttributes.Final | MethodAttributes.Virtual, CallingConventions.Standard, typeof(void), Type.EmptyTypes);
var gen = mBldr.GetILGenerator();
gen.LoadThis();
gen.Emit(OpCodes.Ldfld, fileField);
gen.Emit(OpCodes.Call, typeof(FileStream).GetMethod("Dispose"));
gen.LoadThis();
gen.Emit(OpCodes.Ldnull);
gen.Emit(OpCodes.Stfld, fileField);
gen.Emit(OpCodes.Ret);
}
{
var cBldr = asmTpBldr.DefineTypeInitializer();
var gen = cBldr.GetILGenerator();
const int L_i = 0;
gen.DeclareLocal(typeof(int));
const int L_data = 1;
gen.DeclareLocal(typeof(byte[]));
const int L_i2 = 2;
gen.DeclareLocal(typeof(int));
const int L_len = 3;
gen.DeclareLocal(typeof(int));
{
#if !DisableArrayInit
gen.LoadInt((ulong)tree.Files.Count, 4, false);
gen.Emit(OpCodes.Newarr, typeof(int));
gen.Emit(OpCodes.Dup);
gen.Emit(OpCodes.Ldtoken, initInternalLengthData);
//.........这里部分代码省略.........