本文整理汇总了C#中System.Reflection.Emit.ILGenerator.EmitBestLdArg方法的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator.EmitBestLdArg方法的具体用法?C# ILGenerator.EmitBestLdArg怎么用?C# ILGenerator.EmitBestLdArg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.ILGenerator
的用法示例。
在下文中一共展示了ILGenerator.EmitBestLdArg方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateMethod
public virtual void GenerateMethod(PropertyInfo pi, MethodInfo mi, ILGenerator gen)
{
// Set default values for out parameters
foreach (var par in mi.GetParameters().Where(p => p.IsOut))
{
var defaultAttr = par.GetCustomAttributes(typeof(SafeDefaultAttribute), true)
.Cast<SafeDefaultAttribute>().FirstOrDefault();
var type = par.ParameterType.GetElementType();
gen.EmitBestLdArg((ushort)(par.Position + 1));
if (defaultAttr!=null)
defaultAttr.PushValueAction(gen);
else
PushDefaultReturnValue(gen, type);
gen.EmitStoreToRef(type);
}
// Set default value for return types
if (mi.ReturnType!=typeof(void))
{
MemberInfo attrSource = mi;
if (pi!=null)
attrSource = pi;
var defaultAttr = attrSource.GetCustomAttributes(typeof(SafeDefaultAttribute), true)
.Cast<SafeDefaultAttribute>().FirstOrDefault();
if (defaultAttr!=null)
defaultAttr.PushValueAction(gen);
else
PushDefaultReturnValue(gen, mi.ReturnType);
}
gen.Emit(OpCodes.Ret);
}
示例2: GenerateMethod
public virtual void GenerateMethod(PropertyInfo pi, MethodInfo mi, ILGenerator gen)
{
_rsmc.PutRealSubjectOnStack(gen);
var pars = mi.GetParameters();
for (ushort i = 1; i <= pars.Length; ++i)
gen.EmitBestLdArg(i);
gen.Emit(OpCodes.Callvirt, mi);
gen.Emit(OpCodes.Ret);
}
示例3: GenerateCall
public override void GenerateCall(IProxyModuleCoderAccess proxyModule, ILGenerator gen)
{
var pars = _adaptee.GetParameters();
var targetPars = _target.GetParameters();
var tokens = new object[pars.Length];
// Generate in conversions
for (ushort i = 0; i < pars.Length; ++i)
{
// ReSharper disable once AccessToModifiedClosure
tokens[i] = _paramBindings[i].GenerateInConversion(() => gen.EmitBestLdArg((ushort)(i + 1)), proxyModule, gen);
}
gen.Emit(OpCodes.Callvirt, _target);
// Generate out conversions
for (ushort i = 0; i < pars.Length; ++i)
{
// ReSharper disable once AccessToModifiedClosure
_paramBindings[i].GenerateOutConversion(tokens[i], () => gen.EmitBestLdArg((ushort)(i + 1)), proxyModule, gen);
}
_retValBinding.GenerateConversion(proxyModule, gen);
}
示例4: GenerateMethod
public virtual void GenerateMethod(PropertyInfo pi, MethodInfo mi, ILGenerator gen)
{
var smeType = typeof(ISubjectMethodExists<>).MakeGenericType(_subjectType);
var getSmeMethod = typeof(IMethodExistsProxyMeta).GetMethod("GetSubjectMethodExists").MakeGenericMethod(new[] {_subjectType});
var dmeMethod = smeType.GetMethod("DoesMethodExist", new[] {typeof(int)});
// Locals
var methodExistsProxyMetaLocal = gen.DeclareLocal(typeof(IMethodExistsProxyMeta));
var subjectMethodExistsLocal = gen.DeclareLocal(smeType);
var makingSafeCallLocal = gen.DeclareLocal(typeof(bool));
// Labels
var callOnRealSubjectLabel = gen.DefineLabel();
var makeInnerSubjectCall = gen.DefineLabel();
var retLabel = gen.DefineLabel();
// Check to see if the real subject supports method exists testing
_rsmc.PutRealSubjectOnStack(gen);
gen.Emit(OpCodes.Isinst, typeof(IMethodExistsProxyMeta));
gen.Emit(OpCodes.Dup);
gen.Emit(OpCodes.Stloc, methodExistsProxyMetaLocal);
gen.Emit(OpCodes.Brfalse, callOnRealSubjectLabel);
gen.Emit(OpCodes.Ldloc, methodExistsProxyMetaLocal);
// It does - see if this method exists
gen.Emit(OpCodes.Callvirt, getSmeMethod);
gen.Emit(OpCodes.Dup);
gen.Emit(OpCodes.Stloc, subjectMethodExistsLocal);
gen.Emit(OpCodes.Brfalse_S, callOnRealSubjectLabel);
gen.Emit(OpCodes.Ldloc, subjectMethodExistsLocal);
gen.Emit(OpCodes.Ldc_I4, _methodIndex);
gen.Emit(OpCodes.Callvirt, dmeMethod);
gen.Emit(OpCodes.Ldc_I4_0);
gen.Emit(OpCodes.Ceq, 0);
gen.Emit(OpCodes.Stloc, makingSafeCallLocal);
gen.Emit(OpCodes.Ldloc, makingSafeCallLocal);
gen.Emit(OpCodes.Brfalse_S, callOnRealSubjectLabel);
EmitCtorForSafeNullProxy(gen, _subjectType);
gen.Emit(OpCodes.Br_S, makeInnerSubjectCall);
// Prepare to call on the real subject
gen.MarkLabel(callOnRealSubjectLabel);
_rsmc.PutRealSubjectOnStack(gen);
// Push arguments & call method on the inner subject (real or null proxy)
gen.MarkLabel(makeInnerSubjectCall);
var pars = mi.GetParameters();
for (ushort i = 1; i <= pars.Length; ++i)
gen.EmitBestLdArg(i);
gen.Emit(OpCodes.Callvirt, mi);
// If the method does not exist then the result is already safe and we can return
gen.Emit(OpCodes.Ldloc, makingSafeCallLocal);
gen.Emit(OpCodes.Brtrue_S, retLabel);
// If the return type needs to be made safe then do so
if (mi.ReturnType!=typeof(void) && mi.ReturnType.IsInterface)
{
var notNullLabel = gen.DefineLabel();
gen.Emit(OpCodes.Dup); // duplicate the return value on the stack
gen.Emit(OpCodes.Brtrue_S, notNullLabel); // check it for null
gen.Emit(OpCodes.Pop); // We don't need it - it's always null
EmitCtorForSafeNullProxy(gen, mi.ReturnType);
gen.Emit(OpCodes.Br_S, retLabel);
gen.MarkLabel(notNullLabel);
EmitCtorForSafeDirectProxy(gen, mi.ReturnType);
}
// Return
gen.MarkLabel(retLabel);
gen.Emit(OpCodes.Ret);
++_methodIndex;
}