本文整理汇总了C#中IAssembly.Inject方法的典型用法代码示例。如果您正苦于以下问题:C# IAssembly.Inject方法的具体用法?C# IAssembly.Inject怎么用?C# IAssembly.Inject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAssembly
的用法示例。
在下文中一共展示了IAssembly.Inject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StoreFactoryMap
public void StoreFactoryMap(IAssembly assembly, FactoryMap factoryMap)
{
MethodInfo getTypeFromHandleReflect = typeof (Type).GetMethod("GetTypeFromHandle", new Type[] { typeof(RuntimeTypeHandle) });
MethodReference getTypeFromHandle = assembly.Import(getTypeFromHandleReflect);
TypeReference systemType = assembly.Import(typeof(Type));
TypeReference arrayOfTypes = assembly.Import(typeof(Type[]));
TypeReference arrayOfArrayOfTypes = assembly.Import(typeof(Type[][]));
// Now we create the actual type and stuff...
TypeDefinition mapType = GetFactoryMapType(assembly);
MethodDefinition getFactoriesMethod = new MethodDefinition(FactoryMapMethodName, MethodAttributes.Public, arrayOfArrayOfTypes);
getFactoriesMethod.IsVirtual = true;
mapType.Methods.Add(getFactoriesMethod);
getFactoriesMethod.Body.Variables.Add(new VariableDefinition("map", 0, getFactoriesMethod, arrayOfArrayOfTypes));
getFactoriesMethod.Body.Variables.Add(new VariableDefinition("row", 1, getFactoriesMethod, arrayOfTypes));
getFactoriesMethod.Body.InitLocals = true;
CilWorker worker = getFactoriesMethod.Body.CilWorker;
List<Factory> factories = new List<Factory>(factoryMap.Factories);
worker.Append(worker.Create(OpCodes.Nop));
worker.Append(worker.Create(OpCodes.Ldc_I4, factories.Count));
worker.Append(worker.Create(OpCodes.Newarr, arrayOfTypes));
worker.Append(worker.Create(OpCodes.Stloc_0));
worker.Append(worker.Create(OpCodes.Ldloc_0));
int index = 0;
foreach (Factory factory in factories)
{
worker.Append(worker.Create(OpCodes.Ldc_I4, index));
worker.Append(worker.Create(OpCodes.Ldc_I4, 2));
worker.Append(worker.Create(OpCodes.Newarr, systemType));
worker.Append(worker.Create(OpCodes.Stloc_1));
worker.Append(worker.Create(OpCodes.Ldloc_1));
worker.Append(worker.Create(OpCodes.Ldc_I4_0));
worker.Append(worker.Create(OpCodes.Ldtoken, factory.ObjectType));
worker.Append(worker.Create(OpCodes.Call, getTypeFromHandle));
worker.Append(worker.Create(OpCodes.Stelem_Ref));
worker.Append(worker.Create(OpCodes.Ldloc_1));
worker.Append(worker.Create(OpCodes.Ldc_I4_1));
worker.Append(worker.Create(OpCodes.Ldtoken, factory.FactoryType));
worker.Append(worker.Create(OpCodes.Call, getTypeFromHandle));
worker.Append(worker.Create(OpCodes.Stelem_Ref));
worker.Append(worker.Create(OpCodes.Ldloc_1));
worker.Append(worker.Create(OpCodes.Stelem_Ref));
index++;
worker.Append(worker.Create(OpCodes.Ldloc_0));
}
worker.Append(worker.Create(OpCodes.Ret));
assembly.Inject(mapType);
}