本文整理汇总了C#中Mono.Cecil.Cil.VariableDefinition类的典型用法代码示例。如果您正苦于以下问题:C# VariableDefinition类的具体用法?C# VariableDefinition怎么用?C# VariableDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VariableDefinition类属于Mono.Cecil.Cil命名空间,在下文中一共展示了VariableDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GenerateTypeA
private TypeDefinition GenerateTypeA(AssemblyDefinition assembly)
{
var objType = assembly.MainModule.Import(typeof (object));
// define base class
var aType = new TypeDefinition("A", "", TypeAttributes.Class, objType);
assembly.MainModule.Types.Add(aType);
var typeParameter = new GenericParameter("T", aType);
aType.GenericParameters.Add(typeParameter);
var baseMethod = new MethodDefinition("Get",
MethodAttributes.Assem | MethodAttributes.Virtual |
MethodAttributes.NewSlot, typeParameter);
aType.Methods.Add(baseMethod);
baseMethod.DeclaringType = aType;
var local = new VariableDefinition(typeParameter);
baseMethod.Body.Variables.Add(local);
var cil = baseMethod.Body.CilWorker;
cil.Emit(OpCodes.Ldloca, local);
cil.Emit(OpCodes.Initobj, typeParameter);
cil.Emit(OpCodes.Ldloc, local);
cil.Emit(OpCodes.Ret);
return aType;
}
开发者ID:vestild,项目名称:nemerle,代码行数:27,代码来源:Cecil.GenericBaseClassAndOverrideOfNonPublicVirtualMethod.cs
示例2: InjectAsStreamReader
void InjectAsStreamReader(TypeDefinition targetType, FieldDefinition fieldDefinition)
{
AsStreamReaderMethod = new MethodDefinition("AsStreamReader", staticMethodAttributes, StreamReaderTypeReference);
var streamVariable = new VariableDefinition(StreamTypeReference);
AsStreamReaderMethod.Body.Variables.Add(streamVariable);
var pathParam = new ParameterDefinition(ModuleDefinition.TypeSystem.String);
AsStreamReaderMethod.Parameters.Add(pathParam);
AsStreamReaderMethod.Body.InitLocals = true;
var inst = AsStreamReaderMethod.Body.Instructions;
var skipReturn = Instruction.Create(OpCodes.Nop);
inst.Add(Instruction.Create(OpCodes.Ldsfld, fieldDefinition));
inst.Add(Instruction.Create(OpCodes.Ldarg, pathParam));
inst.Add(Instruction.Create(OpCodes.Callvirt, GetManifestResourceStreamMethod));
inst.Add(Instruction.Create(OpCodes.Stloc, streamVariable));
inst.Add(Instruction.Create(OpCodes.Ldloc, streamVariable));
inst.Add(Instruction.Create(OpCodes.Brtrue_S, skipReturn));
inst.Add(Instruction.Create(OpCodes.Ldnull));
inst.Add(Instruction.Create(OpCodes.Ret));
inst.Add(skipReturn);
inst.Add(Instruction.Create(OpCodes.Ldloc, streamVariable));
inst.Add(Instruction.Create(OpCodes.Newobj, StreamReaderConstructorReference));
inst.Add(Instruction.Create(OpCodes.Ret));
targetType.Methods.Add(AsStreamReaderMethod);
}
开发者ID:huoxudong125,项目名称:Resourcer,代码行数:29,代码来源:HelperClassInjector.cs
示例3: Visit
public void Visit(IBehaviorDefinition behaviorDefinition, CustomAttribute attribute)
{
ILProcessor processor = behaviorDefinition.Body.GetILProcessor();
var pingerDefinition = new VariableDefinition("pinger",
behaviorDefinition.Module.Import(pingType));
behaviorDefinition.Body.Variables.Add(pingerDefinition);
var start = new List<Instruction>
{
processor.Create(OpCodes.Ldstr, behaviorDefinition.Name),
processor.Create(OpCodes.Newobj,
behaviorDefinition.Module.Import(
pingType.GetConstructor(new[]{typeof(string)}))),
processor.Create(OpCodes.Stloc, pingerDefinition),
processor.Create(OpCodes.Ldloc, pingerDefinition),
processor.Create(OpCodes.Callvirt,
behaviorDefinition.Module.Import(pingType.GetMethod("Start",
new Type[] {}))),
};
var end = new List<Instruction>
{
processor.Create(OpCodes.Ldloc, pingerDefinition),
processor.Create(OpCodes.Callvirt,
behaviorDefinition.Module.Import(pingType.GetMethod("End",
new Type[] {})))
};
new InsertionAtStart(processor, behaviorDefinition).Run(start);
new InsertionAtEnd(processor, behaviorDefinition).Run(end);
foreach (var instruction in behaviorDefinition.Body.Instructions)
{
Console.Out.WriteLine("{0}/[{1}]: {2} {3}", instruction.Offset, Sequence(instruction.SequencePoint), instruction.OpCode, instruction.Operand);
}
}
开发者ID:asengupta,项目名称:Exo,代码行数:35,代码来源:PingWeave.cs
示例4: GetServiceHash
/// <summary>
/// Emits a call that obtains the hash code for the current service instance.
/// </summary>
/// <param name="il">The <see cref="ILProcessor"/> that points to the method body.</param>
/// <param name="module">The target module.</param>
/// <param name="serviceInstance">The local variable that contains the service instance.</param>
private void GetServiceHash(ILProcessor il, ModuleDefinition module, VariableDefinition serviceInstance)
{
il.Emit(OpCodes.Ldloc, serviceInstance);
var getHashCodeMethod = module.ImportMethod<object>("GetHashCode");
il.Emit(OpCodes.Callvirt, getHashCodeMethod);
}
开发者ID:philiplaureano,项目名称:Hiro,代码行数:13,代码来源:ServiceInitializer.cs
示例5: Visit
public void Visit(IBehaviorDefinition behaviorDefinition, CustomAttribute attribute)
{
ILProcessor processor = behaviorDefinition.Body.GetILProcessor();
var pingerDefinition = new VariableDefinition("pinger",
behaviorDefinition.Module.Import(breakpointType));
behaviorDefinition.Body.Variables.Add(pingerDefinition);
var sequencedInstructions =
behaviorDefinition.Body.Instructions.Where(instruction => instruction.SequencePoint != null).ToList();
Console.Out.WriteLine(sequencedInstructions.Count);
// var extractedInstructions = Specific(sequencedInstructions, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 20, 21);
var extractedInstructions = Filtered(sequencedInstructions);
foreach (var instruction in extractedInstructions)
{
Type intType = typeof(int);
var breakPointInstructions = new List<Instruction>
{
processor.Create(OpCodes.Newobj, behaviorDefinition.Module.Import(
breakpointType.GetConstructor(new Type[]{}))),
processor.Create(OpCodes.Ldc_I4, instruction.SequencePoint.StartLine),
processor.Create(OpCodes.Ldc_I4, instruction.SequencePoint.StartColumn),
processor.Create(OpCodes.Ldc_I4, instruction.SequencePoint.EndLine),
processor.Create(OpCodes.Ldc_I4, instruction.SequencePoint.EndColumn),
processor.Create(OpCodes.Ldstr, instruction.SequencePoint.Document.Url),
processor.Create(OpCodes.Call,
behaviorDefinition.Module.Import(breakpointType.GetMethod("Activate",
new[] {intType, intType, intType, intType, typeof(string)})))
};
breakPointInstructions.ForEach(bpr => processor.InsertBefore(instruction, bpr));
foreach (var i in behaviorDefinition.Body.Instructions)
{
Console.Out.WriteLine("{0}/[{1}]: {2} {3}", i.Offset, Sequence(i.SequencePoint), i.OpCode, i.Operand);
}
}
}
开发者ID:asengupta,项目名称:Exo,代码行数:35,代码来源:DebugWeave.cs
示例6: AddBeforeAfterInvokerCall
int AddBeforeAfterInvokerCall(int index, PropertyDefinition property)
{
var beforeVariable = new VariableDefinition(msCoreReferenceFinder.ObjectTypeReference);
setMethodBody.Variables.Add(beforeVariable);
var afterVariable = new VariableDefinition(msCoreReferenceFinder.ObjectTypeReference);
setMethodBody.Variables.Add(afterVariable);
var isVirtual = property.GetMethod.IsVirtual;
var getMethod = property.GetMethod.GetGeneric();
index = instructions.Insert(index,
Instruction.Create(OpCodes.Ldarg_0),
CreateCall(getMethod),
//TODO: look into why this box is required
Instruction.Create(OpCodes.Box, property.GetMethod.ReturnType),
Instruction.Create(OpCodes.Stloc, afterVariable),
Instruction.Create(OpCodes.Ldarg_0),
Instruction.Create(OpCodes.Ldstr, property.Name),
Instruction.Create(OpCodes.Ldloc, beforeVariable),
Instruction.Create(OpCodes.Ldloc, afterVariable),
CallEventInvoker()
);
instructions.Prepend(
Instruction.Create(OpCodes.Ldarg_0),
CreateCall(getMethod),
//TODO: look into why this box is required
Instruction.Create(OpCodes.Box, property.GetMethod.ReturnType),
Instruction.Create(OpCodes.Stloc, beforeVariable));
return index + 4;
}
开发者ID:marcuswhit,项目名称:NotifyPropertyWeaver,代码行数:30,代码来源:PropertyWeaver.cs
示例7: EmitBeforeInvoke
public EmitBeforeInvoke(VariableDefinition invocationInfo, VariableDefinition surroundingClassImplementation, VariableDefinition surroundingImplementation, Type registryType)
{
_invocationInfo = invocationInfo;
_surroundingClassImplementation = surroundingClassImplementation;
_surroundingImplementation = surroundingImplementation;
_registryType = registryType;
}
开发者ID:zxl359592450,项目名称:linfu,代码行数:7,代码来源:EmitBeforeInvoke.cs
示例8: MethodBodyRewriterParameters
/// <summary>
/// Initializes a new instance of the <see cref="MethodBodyRewriterParameters"/> class.
/// </summary>
/// <param name="IL">The CilWorker that is responsible for the current method body.</param>
/// <param name="oldInstructions">The value indicating the list of old instructions in the current method body.</param>
/// <param name="interceptionDisabled">The value that determines whether or not interception is disabled.</param>
/// <param name="invocationInfo">The local variable that will store the <see cref="IInvocationInfo"/> instance.</param>
/// <param name="returnValue">The value indicating the local variable that will store the return value.</param>
/// <param name="methodReplacementProvider">The <see cref="IMethodReplacementProvider"/> instance.</param>
/// <param name="aroundInvokeProvider">The <see cref="IAroundInvokeProvider"/> instance.</param>
/// <param name="classMethodReplacementProvider">The class-level<see cref="IMethodReplacementProvider"/> instance.</param>
/// <param name="getMethodReplacementProviderMethod">The functor that resolves the GetMethodReplacementProvider method.</param>
/// <param name="registryType">The interception registry type that will be responsible for handling class-level interception events.</param>
public MethodBodyRewriterParameters(CilWorker IL, IEnumerable<Instruction> oldInstructions,
VariableDefinition interceptionDisabled,
VariableDefinition invocationInfo,
VariableDefinition returnValue,
VariableDefinition methodReplacementProvider,
VariableDefinition aroundInvokeProvider,
VariableDefinition classMethodReplacementProvider,
Func<ModuleDefinition, MethodReference> getMethodReplacementProviderMethod,
Type registryType)
{
if (methodReplacementProvider.VariableType.FullName != typeof(IMethodReplacementProvider).FullName)
throw new ArgumentException("methodReplacementProvider");
if (aroundInvokeProvider.VariableType.FullName != typeof(IAroundInvokeProvider).FullName)
throw new ArgumentException("aroundInvokeProvider");
_cilWorker = IL;
_oldInstructions = oldInstructions;
_interceptionDisabled = interceptionDisabled;
_invocationInfo = invocationInfo;
_returnValue = returnValue;
_methodReplacementProvider = methodReplacementProvider;
_aroundInvokeProvider = aroundInvokeProvider;
_classMethodReplacementProvider = classMethodReplacementProvider;
_getMethodReplacementProviderMethod = getMethodReplacementProviderMethod;
_registryType = registryType;
}
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:40,代码来源:MethodBodyRewriterParameters.cs
示例9: InjectInterceptedMethod
MethodDefinition InjectInterceptedMethod(TypeDefinition targetType, MethodDefinition innerOnPropertyChanging)
{
var delegateHolderInjector = new DelegateHolderInjector
{
TargetTypeDefinition=targetType,
OnPropertyChangingMethodReference = innerOnPropertyChanging,
ModuleWeaver = this
};
delegateHolderInjector.InjectDelegateHolder();
var method = new MethodDefinition(EventInvokerNames.First(), GetMethodAttributes(targetType), ModuleDefinition.TypeSystem.Void);
var propertyName = new ParameterDefinition("propertyName", ParameterAttributes.None, ModuleDefinition.TypeSystem.String);
method.Parameters.Add(propertyName);
if (InterceptorType == InvokerTypes.Before)
{
var before = new ParameterDefinition("before", ParameterAttributes.None, ModuleDefinition.TypeSystem.Object);
method.Parameters.Add(before);
}
var action = new VariableDefinition("firePropertyChanging", ActionTypeReference);
method.Body.Variables.Add(action);
var variableDefinition = new VariableDefinition("delegateHolder", delegateHolderInjector.TypeDefinition);
method.Body.Variables.Add(variableDefinition);
var instructions = method.Body.Instructions;
var last = Instruction.Create(OpCodes.Ret);
instructions.Add(Instruction.Create(OpCodes.Newobj, delegateHolderInjector.ConstructorDefinition));
instructions.Add(Instruction.Create(OpCodes.Stloc_1));
instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
instructions.Add(Instruction.Create(OpCodes.Ldarg_1));
instructions.Add(Instruction.Create(OpCodes.Stfld, delegateHolderInjector.PropertyName));
instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
instructions.Add(Instruction.Create(OpCodes.Stfld, delegateHolderInjector.Target));
instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
instructions.Add(Instruction.Create(OpCodes.Ldftn, delegateHolderInjector.MethodDefinition));
instructions.Add(Instruction.Create(OpCodes.Newobj, ActionConstructorReference));
instructions.Add(Instruction.Create(OpCodes.Stloc_0));
instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
instructions.Add(Instruction.Create(OpCodes.Ldloc_0));
instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
instructions.Add(Instruction.Create(OpCodes.Ldfld, delegateHolderInjector.PropertyName));
if (InterceptorType == InvokerTypes.Before)
{
instructions.Add(Instruction.Create(OpCodes.Ldarg_2));
instructions.Add(Instruction.Create(OpCodes.Call, InterceptMethod));
}
else
{
instructions.Add(Instruction.Create(OpCodes.Call, InterceptMethod));
}
instructions.Add(last);
method.Body.InitLocals = true;
targetType.Methods.Add(method);
return method;
}
开发者ID:Fody,项目名称:PropertyChanging,代码行数:60,代码来源:MethodInjector.cs
示例10: InjectMethod
MethodDefinition InjectMethod(TypeDefinition targetType, string eventInvokerName, FieldReference propertyChangingField)
{
var method = new MethodDefinition(eventInvokerName, GetMethodAttributes(targetType), ModuleDefinition.TypeSystem.Void);
method.Parameters.Add(new ParameterDefinition("propertyName", ParameterAttributes.None, ModuleDefinition.TypeSystem.String));
var handlerVariable = new VariableDefinition(PropChangingHandlerReference);
method.Body.Variables.Add(handlerVariable);
var boolVariable = new VariableDefinition(ModuleDefinition.TypeSystem.Boolean);
method.Body.Variables.Add(boolVariable);
var instructions = method.Body.Instructions;
var last = Instruction.Create(OpCodes.Ret);
instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
instructions.Add(Instruction.Create(OpCodes.Ldfld, propertyChangingField));
instructions.Add(Instruction.Create(OpCodes.Stloc_0));
instructions.Add(Instruction.Create(OpCodes.Ldloc_0));
instructions.Add(Instruction.Create(OpCodes.Ldnull));
instructions.Add(Instruction.Create(OpCodes.Ceq));
instructions.Add(Instruction.Create(OpCodes.Stloc_1));
instructions.Add(Instruction.Create(OpCodes.Ldloc_1));
instructions.Add(Instruction.Create(OpCodes.Brtrue_S, last));
instructions.Add(Instruction.Create(OpCodes.Ldloc_0));
instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
instructions.Add(Instruction.Create(OpCodes.Ldarg_1));
instructions.Add(Instruction.Create(OpCodes.Newobj, ComponentModelPropertyChangingEventConstructorReference));
instructions.Add(Instruction.Create(OpCodes.Callvirt, ComponentModelPropertyChangingEventHandlerInvokeReference));
instructions.Add(last);
method.Body.InitLocals = true;
targetType.Methods.Add(method);
return method;
}
开发者ID:pH200,项目名称:PropertyChanging.ReactiveUI.WinRT,代码行数:34,代码来源:MethodInjector.cs
示例11: CreateTestAssembly
private static AssemblyDefinition CreateTestAssembly(OpCode opCode, bool invert)
{
var name = new AssemblyNameDefinition("TestConditionalsBoundaryTurtle", new Version(1, 0));
var assembly = AssemblyDefinition.CreateAssembly(name, "TestClass", ModuleKind.Dll);
var type = new TypeDefinition("TestConditionalsBoundaryTurtle", "TestClass",
TypeAttributes.Class | TypeAttributes.Public);
var intType = assembly.MainModule.Import(typeof(int));
var boolType = assembly.MainModule.Import(typeof(bool));
var method = new MethodDefinition("TestMethod", MethodAttributes.Public, intType);
var param = new ParameterDefinition("input", ParameterAttributes.In, intType);
method.Parameters.Add(param);
var resultVariable = new VariableDefinition(boolType);
method.Body.Variables.Add(resultVariable);
var processor = method.Body.GetILProcessor();
Instruction loadReturnValueInstruction = processor.Create(OpCodes.Ldloc, resultVariable);
method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, param));
method.Body.Instructions.Add(processor.Create(OpCodes.Ldc_I4, 0));
method.Body.Instructions.Add(processor.Create(opCode));
if (invert)
{
method.Body.Instructions.Add(processor.Create(OpCodes.Ldc_I4, 0));
method.Body.Instructions.Add(processor.Create(OpCodes.Ceq));
}
method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
method.Body.Instructions.Add(loadReturnValueInstruction);
method.Body.Instructions.Add(processor.Create(OpCodes.Ret));
type.Methods.Add(method);
assembly.MainModule.Types.Add(type);
return assembly;
}
开发者ID:dbremner,项目名称:ninjaturtles,代码行数:32,代码来源:ConditionalBoundaryTurtleTests.cs
示例12: HandleDups
public static void HandleDups(MethodDefinition coroutine, OrderedDictionary<Instruction, List<Instruction>> coroutineInstructions, Instruction instruction, List<Instruction> current, TypeReference expectedType, ref VariableDefinition dupLoc)
{
// FIXME: This is kindof a kludge... think on it
if (instruction.Previous.OpCode != OpCodes.Dup)
return;
var action = current.ToArray ();
current.Clear ();
if (dupLoc == null) {
dupLoc = new VariableDefinition (coroutine.Module.Import (typeof (object)));
coroutine.Body.Variables.Add (dupLoc);
}
if (expectedType.IsValueType)
current.Add (Instruction.Create (OpCodes.Box, expectedType));
current.Add (Instruction.Create (OpCodes.Stloc, dupLoc));
current.AddRange (action);
current.Add (Instruction.Create (OpCodes.Ldloc, dupLoc));
if (expectedType.IsValueType) {
current.Add (Instruction.Create (OpCodes.Unbox, expectedType));
current.Add (Instruction.Create (OpCodes.Ldobj, expectedType));
}
}
开发者ID:chkn,项目名称:cirrus,代码行数:27,代码来源:TargetIL_old.cs
示例13: GetMethodReplacementProvider
/// <summary>
/// Initializes a new instance of the <see cref="GetMethodReplacementProvider"/> class.
/// </summary>
/// <param name="methodReplacementProvider">The local variable that contains the <see cref="IMethodReplacementProvider"/> instance.</param>
/// <param name="hostMethod">The target method.</param>
/// <param name="resolveGetProviderMethod">The functor that will resolve the GetProvider method.</param>
public GetMethodReplacementProvider(VariableDefinition methodReplacementProvider, MethodDefinition hostMethod,
Func<ModuleDefinition, MethodReference> resolveGetProviderMethod)
{
_methodReplacementProvider = methodReplacementProvider;
_hostMethod = hostMethod;
_resolveGetProviderMethod = resolveGetProviderMethod;
}
开发者ID:svgorbunov,项目名称:ScrollsModLoader,代码行数:13,代码来源:GetMethodReplacementProvider.cs
示例14: AddV
public static VariableDefinition AddV(this Collection<VariableDefinition> variables,
TypeReference typeReference)
{
VariableDefinition variable = new VariableDefinition(typeReference);
variables.Add(variable);
return variable;
}
开发者ID:JesseBuesking,项目名称:BB.DeepCopy,代码行数:7,代码来源:CecilExtensions.cs
示例15: GetSurroundingClassImplementation
public GetSurroundingClassImplementation(VariableDefinition invocationInfo,
VariableDefinition surroundingClassImplementation, MethodInfo getSurroundingImplementationMethod)
{
_invocationInfo = invocationInfo;
_surroundingClassImplementation = surroundingClassImplementation;
_getSurroundingImplementationMethod = getSurroundingImplementationMethod;
}
开发者ID:leehavin,项目名称:linfu,代码行数:7,代码来源:GetSurroundingClassImplementation.cs
示例16: AddBeforeAfterInvokerCall
int AddBeforeAfterInvokerCall(int index, PropertyDefinition property)
{
var beforeVariable = new VariableDefinition(typeSystem.Object);
setMethodBody.Variables.Add(beforeVariable);
var afterVariable = new VariableDefinition(typeSystem.Object);
setMethodBody.Variables.Add(afterVariable);
var getMethod = property.GetMethod.GetGeneric();
index = instructions.Insert(index,
Instruction.Create(OpCodes.Ldarg_0),
CreateCall(getMethod),
Instruction.Create(OpCodes.Box, property.GetMethod.ReturnType),
Instruction.Create(OpCodes.Stloc, afterVariable),
Instruction.Create(OpCodes.Ldarg_0),
Instruction.Create(OpCodes.Ldstr, property.Name),
Instruction.Create(OpCodes.Ldloc, beforeVariable),
Instruction.Create(OpCodes.Ldloc, afterVariable),
CallEventInvoker()
);
instructions.Prepend(
Instruction.Create(OpCodes.Ldarg_0),
CreateCall(getMethod),
Instruction.Create(OpCodes.Box, property.GetMethod.ReturnType),
Instruction.Create(OpCodes.Stloc, beforeVariable));
return index + 4;
}
开发者ID:halad,项目名称:PropertyChanged,代码行数:27,代码来源:PropertyWeaver.cs
示例17: GetSurroundingImplementationInstance
public GetSurroundingImplementationInstance(VariableDefinition aroundInvokeProvider, VariableDefinition invocationInfo, VariableDefinition surroundingImplementation, Instruction skipGetSurroundingImplementation)
{
_aroundInvokeProvider = aroundInvokeProvider;
_invocationInfo = invocationInfo;
_surroundingImplementation = surroundingImplementation;
_skipGetSurroundingImplementation = skipGetSurroundingImplementation;
}
开发者ID:leehavin,项目名称:linfu,代码行数:7,代码来源:GetSurroundingImplementationInstance.cs
示例18: InvokeMethodReplacement
public InvokeMethodReplacement(Instruction executeOriginalInstructions, VariableDefinition methodReplacementProvider, VariableDefinition classMethodReplacementProvider, VariableDefinition invocationInfo)
{
_executeOriginalInstructions = executeOriginalInstructions;
_methodReplacementProvider = methodReplacementProvider;
_classMethodReplacementProvider = classMethodReplacementProvider;
_invocationInfo = invocationInfo;
}
开发者ID:zxl359592450,项目名称:linfu,代码行数:7,代码来源:InvokeMethodReplacement.cs
示例19: AddCollectionLoop
private static void AddCollectionLoop(Collection<Instruction> ins, VariableDefinition leftEnumerator, VariableDefinition leftHasNext,
VariableDefinition rightEnumerator, VariableDefinition rightHasNext)
{
var loopBegin = Instruction.Create(OpCodes.Nop);
ins.Add(loopBegin);
AddMoveNext(ins, leftEnumerator, leftHasNext);
AddMoveNext(ins, rightEnumerator, rightHasNext);
ins.IfAnd(
c => AddCheckHasNext(c, leftHasNext, false),
c => AddCheckHasNext(c, rightHasNext, false),
t => AddReturnTrue(t),
e =>
{
e.IfAnd(
c => AddCheckHasNext(c, leftHasNext, true),
c => AddCheckHasNext(c, rightHasNext, true),
t =>
{
t.If(
c => AddCheckCurrent(c, leftEnumerator, rightEnumerator),
tt => AddRerurnFalse(tt));
},
e2 =>
{
ins.Add(Instruction.Create(OpCodes.Ldc_I4_0));
ins.Add(Instruction.Create(OpCodes.Ret));
});
});
ins.Add(Instruction.Create(OpCodes.Br, loopBegin));
}
开发者ID:kzaikin,项目名称:Equals,代码行数:33,代码来源:CollectionHelperInjector.cs
示例20: CreateTestAssembly
private static AssemblyDefinition CreateTestAssembly()
{
var name = new AssemblyNameDefinition("TestBranchConditionTurtle", new Version(1, 0));
var assembly = AssemblyDefinition.CreateAssembly(name, "TestClass", ModuleKind.Dll);
var type = new TypeDefinition("TestBranchConditionTurtle", "TestClass",
TypeAttributes.Class | TypeAttributes.Public);
var intType = assembly.MainModule.Import(typeof(int));
var boolType = assembly.MainModule.Import(typeof(bool));
var method = new MethodDefinition("TestMethod", MethodAttributes.Public, intType);
var leftParam = new ParameterDefinition("left", ParameterAttributes.In, intType);
var rightParam = new ParameterDefinition("right", ParameterAttributes.In, intType);
method.Parameters.Add(leftParam);
method.Parameters.Add(rightParam);
var resultVariable = new VariableDefinition(boolType);
method.Body.Variables.Add(resultVariable);
var processor = method.Body.GetILProcessor();
Instruction loadReturnValueInstruction = processor.Create(OpCodes.Ldloc, resultVariable);
Instruction storeTrueInReturnValueInstruction = processor.Create(OpCodes.Ldc_I4, -1);
method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, leftParam));
method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, rightParam));
method.Body.Instructions.Add(processor.Create(OpCodes.Ceq));
method.Body.Instructions.Add(processor.Create(OpCodes.Brtrue_S, storeTrueInReturnValueInstruction));
method.Body.Instructions.Add(processor.Create(OpCodes.Ldc_I4, 0));
method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
method.Body.Instructions.Add(processor.Create(OpCodes.Br_S, loadReturnValueInstruction));
method.Body.Instructions.Add(storeTrueInReturnValueInstruction);
method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
method.Body.Instructions.Add(loadReturnValueInstruction);
method.Body.Instructions.Add(processor.Create(OpCodes.Ret));
type.Methods.Add(method);
assembly.MainModule.Types.Add(type);
return assembly;
}
开发者ID:dbremner,项目名称:ninjaturtles,代码行数:35,代码来源:BranchConditionTurtleTests.cs
注:本文中的Mono.Cecil.Cil.VariableDefinition类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论