本文整理汇总了C#中System.Reflection.Emit.ILGenerator.EmitBox方法的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator.EmitBox方法的具体用法?C# ILGenerator.EmitBox怎么用?C# ILGenerator.EmitBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.ILGenerator
的用法示例。
在下文中一共展示了ILGenerator.EmitBox方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitFinish
public void EmitFinish(ILGenerator generator)
{
if (_methodReturn == _delegateReturn)
return;
if (_methodReturn == typeof (void))
generator.Emit(OpCodes.Ldnull);
else if (_methodReturn.IsValueType && !_delegateReturn.IsValueType)
generator.EmitBox(_methodReturn);
}
示例2: EmitLoad
public override void EmitLoad(ILGenerator generator)
{
EmitLoadToStack(generator);
var mt = _methodParameter.ParameterType.RemoveByRef();
var dt = _delegateParameter.ParameterType.RemoveByRef();
if (dt.IsValueType && !mt.IsValueType)
generator.EmitBox(dt);
else if (!mt.IsAssignableFrom(dt))
generator.EmitUnBoxAnyOrCastClass(mt);
}
示例3: EmitFinish
public override void EmitFinish(ILGenerator generator)
{
if (!_needLocalVariable)
return;
generator.EmitLdarg(_delegateParameterIndex);
generator.EmitLdloc(_localVariable.LocalIndex);
var mt = _methodParameter.ParameterType.RemoveByRef();
var dt = _delegateParameter.ParameterType.RemoveByRef();
if (mt.IsValueType && !dt.IsValueType)
generator.EmitBox(mt);
generator.EmitStind(dt);
}
示例4: EmitPrepare
public override void EmitPrepare(ILGenerator generator)
{
base.EmitPrepare(generator);
if (!_needLocalVariable)
return;
generator.EmitLdarg(_delegateParameterIndex);
var dt = _delegateParameter.ParameterType.RemoveByRef();
var mt = _methodParameter.ParameterType.RemoveByRef();
if (_delegateParameter.ParameterType.IsByRef)
generator.EmitLdind(dt);
if (dt.IsValueType && !mt.IsValueType)
generator.EmitBox(dt);
else if (!mt.IsAssignableFrom(dt))
generator.EmitUnBoxAnyOrCastClass(mt);
generator.EmitStloc(_localVariable.LocalIndex);
}
示例5: LoadArguments
/// <summary>
/// Loads the arguments onto the stack.
/// </summary>
/// <param name="ilGenerator">The intermediate language generator.</param>
/// <param name="parameterTypes">The parameter types.</param>
/// <param name="parametersLocalBuilder">The parameters local builder.</param>
private static void LoadArguments(ILGenerator ilGenerator, IList<Type> parameterTypes, LocalBuilder parametersLocalBuilder)
{
for (var index = 0; index < parameterTypes.Count; index++)
{
var parameterType = parameterTypes[index];
ilGenerator.Emit(OpCodes.Ldloc, parametersLocalBuilder);
ilGenerator.EmitLoadValue(index);
ilGenerator.EmitLoadArgument(index + 1);
if (parameterType.IsByRef)
{
var elementType = parameterType.GetElementType();
ilGenerator.EmitLoadIndirect(parameterType);
ilGenerator.EmitBox(elementType);
}
else
{
ilGenerator.EmitBox(parameterType);
}
ilGenerator.Emit(OpCodes.Stelem_Ref);
}
}
示例6: RestoreByReferenceParameterValues
/// <summary>
/// Restores the by reference parameter values.
/// </summary>
/// <param name="ilGenerator">The intermediate language generator.</param>
/// <param name="argumentIndex">The argument index.</param>
/// <param name="parameterTypes">The parameter types.</param>
/// <param name="parameterValueLocalBuilders">The parameter value local builders.</param>
private static void RestoreByReferenceParameterValues(ILGenerator ilGenerator, int argumentIndex, IList<Type> parameterTypes, IList<LocalBuilder> parameterValueLocalBuilders)
{
for (var index = 0; index < parameterTypes.Count; index++)
{
var parameterType = parameterTypes[index];
if (!parameterType.IsByRef)
continue;
var parameterLocalBuilder = parameterValueLocalBuilders[index];
var elementType = parameterType.GetElementType();
ilGenerator.EmitLoadArgument(argumentIndex);
ilGenerator.EmitLoadValue(index);
ilGenerator.Emit(OpCodes.Ldloc, parameterLocalBuilder);
ilGenerator.EmitBox(elementType);
ilGenerator.Emit(OpCodes.Stelem_Ref);
}
}