本文整理汇总了C#中ILGen.EmitBoxing方法的典型用法代码示例。如果您正苦于以下问题:C# ILGen.EmitBoxing方法的具体用法?C# ILGen.EmitBoxing怎么用?C# ILGen.EmitBoxing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILGen
的用法示例。
在下文中一共展示了ILGen.EmitBoxing方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
public override void Compile(Executive engine, object form, ILGen il, LocalAccess locals, Stack<Type> st, object[] args)
{
if (args.Length != 2)
throw new ArgumentException("Unproperly formated cast expression");
engine.CompileExpr(il, locals, st, args[0]);
Type type = args[1] as Type;
if (type == null)
throw new ArgumentException("Expecting type value");
Type curr_type = st.Pop();
if (curr_type.IsValueType)
{
if (type == typeof(System.Object))
il.EmitBoxing(curr_type);
else if (curr_type != type)
throw new InvalidCastException();
}
else
{
il.Emit(OpCodes.Isinst, type);
il.Emit(OpCodes.Dup);
Label ok = il.DefineLabel();
il.Emit(OpCodes.Brtrue_S, ok);
il.EmitCall(_raiseInvalidCast);
il.MarkLabel(ok);
if (type.IsValueType)
il.EmitUnbox(type);
}
st.Push(type);
}
示例2: EmitArgument
internal static ReturnFixer EmitArgument(ILGen cg, int argIndex, Type argType) {
cg.EmitLoadArg(argIndex);
if (!argType.IsByRef) {
cg.EmitBoxing(argType);
return null;
}
Type elementType = argType.GetElementType();
cg.EmitLoadValueIndirect(elementType);
Type concreteType = typeof(StrongBox<>).MakeGenericType(elementType);
cg.EmitNew(concreteType, new Type[] { elementType });
LocalBuilder refSlot = cg.DeclareLocal(concreteType);
cg.Emit(OpCodes.Dup);
cg.Emit(OpCodes.Stloc, refSlot);
return new ReturnFixer(refSlot, argIndex, argType);
}
示例3: EmitArgument
public static ReturnFixer EmitArgument(ILGen il, ParameterInfo parameter, int index) {
il.EmitLoadArg(index);
if (parameter.ParameterType.IsByRef) {
Type elementType = parameter.ParameterType.GetElementType();
Type concreteType = typeof(StrongBox<>).MakeGenericType(elementType);
LocalBuilder refSlot = il.DeclareLocal(concreteType);
il.EmitLoadValueIndirect(elementType);
ConstructorInfo ci = concreteType.GetConstructor(new Type[] { elementType });
il.Emit(OpCodes.Newobj, ci);
il.Emit(OpCodes.Stloc, refSlot);
il.Emit(OpCodes.Ldloc, refSlot);
return new ReturnFixer(refSlot, parameter, index);
} else {
il.EmitBoxing(parameter.ParameterType);
return null;
}
}
示例4: CompileExpr
//.........这里部分代码省略.........
FuncName name = new FuncName(head, parameterTypes);
FuncBase body = GetFunc(name, false);
if (body == null)
{
bool successed = false;
if (parameterTypes.Length == 2)
{
Type castType = ValueProxy.GetType(parameterTypes[0], parameterTypes[1]);
ValueConverter converter1 = FindConverter(parameterTypes[0], castType);
ValueConverter converter2 = FindConverter(parameterTypes[1], castType);
body = GetFunc(new FuncName(name.ID, new Type[] { castType, castType }), false);
if (body != null && converter1 != null && converter2 != null)
{
LocalBuilder localVar = il.DeclareLocal(parameterTypes[1]);
il.Emit(OpCodes.Stloc, localVar);
converter1.Compile(this, il, locals, parameterTypes[0]);
il.Emit(OpCodes.Ldloc, localVar);
il.FreeLocal(localVar);
converter2.Compile(this, il, locals, parameterTypes[1]);
successed = true;
}
}
if (!successed)
{
body = GetFunc(name, true);
if (body == null)
throw new UnknownFuncCall(name.ToString());
else
{
LocalBuilder[] localVar = new LocalBuilder[parameterTypes.Length];
for (int k = localVar.Length - 1; k >= 0; k--)
{
localVar[k] = il.DeclareLocal(parameterTypes[k]);
il.Emit(OpCodes.Stloc, localVar[k]);
}
Type[] new_parameter_types = new Type[parameterTypes.Length];
for (int k = 0; k < localVar.Length; k++)
{
il.Emit(OpCodes.Ldloc, localVar[k]);
if (body.Name.GetParameterType(k) != parameterTypes[k])
{
if (parameterTypes[k].IsValueType)
il.EmitBoxing(parameterTypes[k]);
else if (ValueProxy.IsProxyType(parameterTypes[k]))
il.EmitPropertyGet(typeof(ValueProxy), "Value");
new_parameter_types[k] = typeof(System.Object);
}
else
new_parameter_types[k] = parameterTypes[k];
il.FreeLocal(localVar[k]);
}
parameterTypes = new_parameter_types;
}
}
}
Type resType = body.Compile(this, il, locals, parameterTypes);
if (resType == typeof(System.Boolean))
{ // Implict boolean convertion
Label l_false = il.DefineLabel();
Label end = il.DefineLabel();
il.Emit(OpCodes.Brfalse_S, l_false);
il.Emit(OpCodes.Ldsfld, typeof(RuntimeOps).GetField("True"));
il.Emit(OpCodes.Br_S, end);
il.MarkLabel(l_false);
il.EmitNull();
il.MarkLabel(end);
st.Push(typeof(System.Object));
}
else if (resType == typeof(void))
{ // assume that all procedures returns t
il.Emit(OpCodes.Ldsfld, typeof(RuntimeOps).GetField("True"));
st.Push(typeof(System.Object));
}
else
st.Push(resType);
}
}
else
if (Lisp.IsFunctor(Lisp.Car(lval), Lisp.LAMBDA))
{
object form = Lisp.Car(lval);
object body = Lisp.Car(Lisp.Cddr(form));
object tail = Lisp.Cdr(lval);
LambdaExpr lambda = new LambdaExpr(null, CreateParameters(Lisp.Arg1(form)),
typeof(System.Object), body);
List<Type> parameterTypesList = new List<Type>();
foreach (object a in Lisp.getIterator(tail))
{
CompileExpr(il, locals, st, a);
parameterTypesList.Add(st.Pop());
}
Type[] parameterTypes = parameterTypesList.ToArray();
FuncName name = new FuncName(null, parameterTypes);
if (!lambda.Name.Match(name, true))
throw new InvalidOperationException("Lambda parameters does not match");
st.Push(lambda.Compile(this, il, locals, parameterTypes));
}
else
throw new ArgumentException("Unproperly formated expression");
}