本文整理汇总了C#中System.Reflection.Emit.ILGenerator.EmitLoadLocal方法的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator.EmitLoadLocal方法的具体用法?C# ILGenerator.EmitLoadLocal怎么用?C# ILGenerator.EmitLoadLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.ILGenerator
的用法示例。
在下文中一共展示了ILGenerator.EmitLoadLocal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Weave
public void Weave(ILGenerator ilGenerator)
{
var typeofType = typeof(Type);
var typeofObject = typeof(object);
FieldBuilder contractFieldBuilder = null;
LocalBuilder typesArrayLocalBuilder = null;
LocalBuilder tempTypesArrayLocalBuilder = null;
var typeofArrayOfTypes = typeofType.MakeArrayType();
var weavingSettings = aspectWeavingSettings.WeavingSettings;
var getTypeFromHandleMethodInfo = typeofType.GetMethod("GetTypeFromHandle");
var localBuilderRepository = aspectWeavingSettings.LocalBuilderRepository;
typesArrayLocalBuilder = localBuilderRepository.Declare(() => {
return ilGenerator.DeclareLocal(typeofArrayOfTypes);
});
tempTypesArrayLocalBuilder = ilGenerator.DeclareLocal(typeofArrayOfTypes);
ilGenerator.EmitPushInteger(parameters.Length);
ilGenerator.Emit(OpCodes.Newarr, typeofType);
ilGenerator.EmitStoreLocal(tempTypesArrayLocalBuilder);
parameters.ForEach((parameter, i) => {
var isByRef = parameter.IsByRef;
if (isByRef) {
parameter = parameter.GetElementType();
}
ilGenerator.EmitLoadLocal(tempTypesArrayLocalBuilder);
ilGenerator.EmitPushInteger(i);
ilGenerator.Emit(OpCodes.Ldtoken, parameter);
ilGenerator.Emit(OpCodes.Call, getTypeFromHandleMethodInfo);
if (isByRef) {
ilGenerator.Emit(OpCodes.Callvirt, typeofType.GetMethod("MakeByRefType"));
}
ilGenerator.Emit(OpCodes.Stelem_Ref);
});
ilGenerator.EmitLoadLocal(tempTypesArrayLocalBuilder);
ilGenerator.EmitStoreLocal(typesArrayLocalBuilder);
ilGenerator.EmitLoadArg(0);
contractFieldBuilder = weavingSettings.TypeDefinition.GetFieldBuilder(weavingSettings.ContractType);
ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
ilGenerator.Emit(OpCodes.Callvirt, typeofObject.GetMethod("GetType"));
ilGenerator.Emit(OpCodes.Ldstr, method.Name);
ilGenerator.EmitLoadLocal(typesArrayLocalBuilder);
ilGenerator.Emit(OpCodes.Callvirt, typeofType.GetMethod("GetMethod", new[] { typeof(string), typeof(Type[]) }));
ilGenerator.EmitStoreLocal(methodLocalBuilder);
}
示例2: WeaveAspectArg
protected override void WeaveAspectArg(ILGenerator ilGenerator)
{
var localBuilderRepository = aspectWeavingSettings.LocalBuilderRepository;
var previousAspectArgsLocalBuilder = localBuilderRepository.Get(topAspectInScopeArgType);
ilGenerator.EmitLoadLocal(previousAspectArgsLocalBuilder);
}
示例3: BuildArguments
public override LocalBuilder BuildArguments(ILGenerator ilGenerator)
{
LocalBuilder propertyLocalBuilder = null;
FieldBuilder contractFieldBuilder = null;
LocalBuilder aspectArgLocalBuilder = null;
ConstructorInfo ctorInterceptionArgs = null;
AbstractAspectPropertyArgsWeaver methodWeaver = null;
propertyLocalBuilder = LocalBuilderRepository.Declare(() => {
return ilGenerator.DeclareLocal(typeof(PropertyInfo));
});
ctorInterceptionArgs = ArgumentType.GetConstructors()[0];
aspectArgLocalBuilder = ilGenerator.DeclareLocal(ArgumentType);
contractFieldBuilder = WeavingSettings.TypeDefinition.GetFieldBuilder(WeavingSettings.ContractType);
methodWeaver = new AspectArgsGetPropertyWeaver(Member, propertyLocalBuilder, aspectWeavingSettings);
methodWeaver.Weave(ilGenerator);
ilGenerator.EmitLoadArg(0);
ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
ilGenerator.EmitLoadLocal(propertyLocalBuilder);
ilGenerator.Emit(OpCodes.Ldsfld, BindingsDependency);
ilGenerator.Emit(OpCodes.Newobj, ctorInterceptionArgs);
ilGenerator.EmitStoreLocal(aspectArgLocalBuilder);
return aspectArgLocalBuilder;
}
示例4: BuildArguments
public override LocalBuilder BuildArguments(ILGenerator ilGenerator)
{
var typeDefinition = (IAspectTypeDefinition)WeavingSettings.TypeDefinition;
var aspectArgLocalBuilder = ilGenerator.DeclareLocal(ArgumentType);
var eventLocalBuilder = ilGenerator.DeclareLocal(typeof(EventInfo));
var contractFieldBuilder = typeDefinition.GetFieldBuilder(WeavingSettings.ContractType);
var eventArgumentContract = Member.ToEventArgumentContract();
var eventBrokerProperty = eventArgumentContract.GetProperty("EventBroker");
var eventBrokerType = eventBrokerProperty.PropertyType;
var handlerType = eventBrokerType.GetGenericArguments().First();
var delegateLocalBuilder = ilGenerator.DeclareLocal(handlerType);
var delegateCtor = handlerType.GetConstructor(new[] { typeof(object), typeof(IntPtr) });
var eventBrokerFieldBuilder = typeDefinition.GetEventFieldBuilder(Member.Name, eventBrokerType);
var eventBrokerFieldTypeDefinition = typeDefinition.GetEventBrokerFielTypeDefinition(Member);
var ctorInterceptionArgs = ArgumentType.GetConstructors().Single(ctor => ctor.GetParameters().Length != 0);
var parameters = handlerType.GetInvokeMethod().GetParameters();
ilGenerator.EmitLoadArg(1);
ilGenerator.Emit(OpCodes.Ldftn, eventBrokerFieldTypeDefinition.Event.EventHandlerType.GetInvokeMethod());
ilGenerator.Emit(OpCodes.Newobj, delegateCtor);
ilGenerator.EmitStoreLocal(delegateLocalBuilder);
ilGenerator.EmitLoadArg(0);
ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
ilGenerator.Emit(OpCodes.Callvirt, typeof(object).GetMethod("GetType"));
ilGenerator.Emit(OpCodes.Ldstr, Member.Name);
ilGenerator.Emit(OpCodes.Callvirt, typeof(Type).GetMethod("GetEvent", new[] { typeof(string) }));
ilGenerator.EmitStoreLocal(eventLocalBuilder);
ilGenerator.EmitLoadArg(0);
ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
ilGenerator.EmitLoadLocal(eventLocalBuilder);
ilGenerator.EmitLoadLocal(delegateLocalBuilder);
ilGenerator.Emit(OpCodes.Ldsfld, BindingsDependency);
ilGenerator.EmitLoadArg(0);
ilGenerator.Emit(OpCodes.Ldfld, eventBrokerFieldBuilder);
parameters.ForEach(1, (arg, i) => {
var property = ArgumentType.GetProperty("Arg{0}".Fmt(i));
ilGenerator.EmitLoadArg(1);
ilGenerator.Emit(OpCodes.Callvirt, property.GetGetMethod());
});
ilGenerator.Emit(OpCodes.Newobj, ctorInterceptionArgs);
ilGenerator.EmitStoreLocal(aspectArgLocalBuilder);
return aspectArgLocalBuilder;
}
示例5: Weave
public void Weave(ILGenerator ilGenerator)
{
var typeofException = typeof(Exception);
LocalBuilder exceptionLocalBuilder = null;
var typeofFlowBehavior = typeof(FlowBehavior);
LocalBuilder flowBehavoiurLocalBuilder = null;
var afterRethrowLabel = ilGenerator.DefineLabel();
var throwFlowBehaviorLabel = ilGenerator.DefineLabel();
var rethrowFlowBehaviorLabel = ilGenerator.DefineLabel();
var argsImplLocalBuilder = localBuilderRepository.Get(aspectArgumentType);
var jumpTable = new[] { throwFlowBehaviorLabel, rethrowFlowBehaviorLabel };
var setExceptionMethodInfo = aspectArgumentType.GetProperty("Exception").GetSetMethod();
var flowBehaviorMethodInfo = aspectArgumentType.GetProperty("FlowBehavior").GetGetMethod();
exceptionLocalBuilder = localBuilderRepository.GetOrDeclare(typeofException, () => {
return ilGenerator.DeclareLocal(typeofException);
});
flowBehavoiurLocalBuilder = localBuilderRepository.GetOrDeclare(typeofFlowBehavior, () => {
return ilGenerator.DeclareLocal(typeofFlowBehavior);
});
ilGenerator.BeginCatchBlock(typeofException);
ilGenerator.EmitStoreLocal(exceptionLocalBuilder);
ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
ilGenerator.EmitLoadLocal(exceptionLocalBuilder);
ilGenerator.Emit(OpCodes.Callvirt, setExceptionMethodInfo);
catchWeavers.ForEach(weaver => weaver.Weave(ilGenerator));
ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
ilGenerator.Emit(OpCodes.Callvirt, flowBehaviorMethodInfo);
ilGenerator.EmitStoreLocal(flowBehavoiurLocalBuilder);
ilGenerator.EmitLoadLocal(flowBehavoiurLocalBuilder);
ilGenerator.EmitPushInteger(1);
ilGenerator.Emit(OpCodes.Sub);
ilGenerator.Emit(OpCodes.Switch, jumpTable);
ilGenerator.Emit(OpCodes.Br_S, afterRethrowLabel);
ilGenerator.MarkLabel(throwFlowBehaviorLabel);
ilGenerator.EmitLoadLocal(exceptionLocalBuilder);
ilGenerator.Emit(OpCodes.Throw);
ilGenerator.MarkLabel(rethrowFlowBehaviorLabel);
ilGenerator.Emit(OpCodes.Rethrow);
ilGenerator.MarkLabel(afterRethrowLabel);
}
示例6: RestoreArgsIfNeeded
public override void RestoreArgsIfNeeded(ILGenerator ilGenerator)
{
byRefParamslocalBuilderMap.ForEach(argPosition => {
var property = previousAspectArgType.GetProperty("Arg{0}".Fmt(argPosition));
ilGenerator.EmitLoadLocal(argsLocalBuilder);
ilGenerator.EmitLoadArg(argPosition);
ilGenerator.Emit(OpCodes.Ldind_I4);
ilGenerator.Emit(OpCodes.Callvirt, property.GetSetMethod());
});
}
示例7: Weave
public virtual void Weave(ILGenerator ilGenerator)
{
LocalBuilder argsLocalBuilder = null;
var aspectMember = aspectRepository.GetAspectFieldByType(aspectType);
var adviceMethod = aspectMember.FieldType.GetMethod(AdviceName);
argsLocalBuilder = localBuilderRepository.Get(argumentsWeavingSettings.ArgumentType);
ilGenerator.Emit(OpCodes.Ldsfld, aspectMember);
ilGenerator.EmitLoadLocal(argsLocalBuilder);
ilGenerator.Emit(OpCodes.Callvirt, adviceMethod);
}
示例8: Weave
public void Weave(ILGenerator ilGenerator)
{
MethodInfo returnValueGetMethod = null;
LocalBuilder argsImplLocalBuilder = null;
var argumentType = argumentsWeavingSetings.ArgumentType;
var aspectArgsType = GetAspectArgsType();
argsImplLocalBuilder = localBuilderRepository.Get(argumentType);
ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
returnValueGetMethod = aspectArgsType.GetProperty("ReturnValue").GetGetMethod();
ilGenerator.Emit(OpCodes.Callvirt, returnValueGetMethod);
}
示例9: Weave
public override void Weave(ILGenerator ilGenerator)
{
LocalBuilder aspectArgLocalBuilder = null;
var argumentType = argumentsWeavingSettings.ArgumentType;
var valueProperty = argumentType.GetProperty("Value");
argumentsWeaver.Weave(ilGenerator);
weaver.Weave(ilGenerator);
aspectArgLocalBuilder = localBuilderRepository.Get(argumentType);
ilGenerator.EmitLoadLocal(aspectArgLocalBuilder);
ilGenerator.Emit(OpCodes.Callvirt, valueProperty.GetGetMethod());
}
示例10: RestoreArgsIfNeeded
public override void RestoreArgsIfNeeded(ILGenerator ilGenerator)
{
byRefParamslocalBuilderMap.ForEach(keyValue => {
var argPosition = keyValue.Key;
var localBuilder = keyValue.Value;
var property = aspectArgumentType.GetProperty("Arg{0}".Fmt(argPosition));
WeaveAspectArg(ilGenerator);
ilGenerator.EmitLoadLocal(localBuilder);
ilGenerator.Emit(OpCodes.Callvirt, property.GetSetMethod());
});
}
示例11: WeaveFunction
protected override void WeaveFunction(ILGenerator ilGenerator)
{
var setReturnValueWeaver = new SetReturnValueWeaver(topAspectInScopeArgType);
var argsImplLocalBuilder = localBuilderRepository.Get(topAspectInScopeArgType);
byRefArgumentStoreWeaver.StoreArgsIfNeeded(ilGenerator);
ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
argumentsWeaver.Weave(ilGenerator);
ilGenerator.Emit(OpCodes.Callvirt, Method);
setReturnValueWeaver.Weave(ilGenerator);
byRefArgumentStoreWeaver.RestoreArgsIfNeeded(ilGenerator);
}
示例12: Weave
public void Weave(ILGenerator ilGenerator)
{
LocalBuilder aspectArgLocalBuilder = null;
var argumentType = argumentsWeavingSettings.ArgumentType;
var propertyAspectArgument = property.ToPropertyAspectArgument();
var propertyArgumentContract = property.ToPropertyArgumentContract();
var localBuilderRepository = aspectWeavingSettings.LocalBuilderRepository;
var propertyAspectArgumentProperty = propertyAspectArgument.GetProperty("Value");
var propertyArgumentContractProperty = propertyArgumentContract.GetProperty("Value");
ilGenerator.EmitLoadArg(2);
aspectArgLocalBuilder = localBuilderRepository.Get(argumentType);
ilGenerator.EmitLoadLocal(aspectArgLocalBuilder);
ilGenerator.Emit(OpCodes.Callvirt, propertyAspectArgumentProperty.GetGetMethod());
ilGenerator.Emit(OpCodes.Callvirt, propertyArgumentContractProperty.GetSetMethod());
}
示例13: StoreArgsIfNeeded
public override void StoreArgsIfNeeded(ILGenerator ilGenerator)
{
argsLocalBuilder = localBuilderRepository.GetOrDeclare(previousAspectArgType, () => {
return ilGenerator.DeclareLocal(previousAspectArgType);
});
parameters.ForEach(param => {
int argPosition = param.Position + 1;
var property = previousAspectArgType.GetProperty("Arg{0}".Fmt(argPosition));
ilGenerator.EmitLoadArg(argPosition);
byRefParamslocalBuilderMap.Add(argPosition);
ilGenerator.EmitLoadLocal(argsLocalBuilder);
ilGenerator.Emit(OpCodes.Callvirt, property.GetGetMethod());
ilGenerator.Emit(OpCodes.Stind_I4);
});
}
示例14: Weave
public virtual void Weave(ILGenerator ilGenerator)
{
MethodInfo mapGenericMethod = null;
Func<int, MethodInfo> getMappingArgsMethod = null;
var argsImplLocalBuilder = localBuilderRepository.Get(aspectArgumentType);
if (mappingParameters.Length > 0) {
getMappingArgsMethod = argumentsSettings.IsFunction() ?
aspectWeavingSettings.AspectArgsMapper.GetFunctionMappingArgs :
(Func<int, MethodInfo>)aspectWeavingSettings.AspectArgsMapper.GetActionMappingArgs;
mapGenericMethod = getMappingArgsMethod(mappingParameters.Length);
mapGenericMethod = mapGenericMethod.MakeGenericMethod(mappingParameters);
ilGenerator.EmitLoadLocal(argsImplLocalBuilder);
WeaveAspectArg(ilGenerator);
ilGenerator.Emit(OpCodes.Call, mapGenericMethod);
}
}
示例15: WeaveAspectArg
protected override void WeaveAspectArg(ILGenerator ilGenerator)
{
var topAspectInScopeLocalBuilder = localBuilderRepository.Get(topAspectInScopeArgType);
ilGenerator.EmitLoadLocal(topAspectInScopeLocalBuilder);
}