本文整理汇总了C#中Emitter.EmitBox方法的典型用法代码示例。如果您正苦于以下问题:C# Emitter.EmitBox方法的具体用法?C# Emitter.EmitBox怎么用?C# Emitter.EmitBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Emitter
的用法示例。
在下文中一共展示了Emitter.EmitBox方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
public override void Compile(Emitter.Emitter emitter)
{
var leftType = Left.GetExpressionType(emitter);
var rightType = Right.GetExpressionType(emitter);
// an array of values
if (rightType == leftType + "[]")
{
Right.Compile(emitter);
Left.Compile(emitter);
if (leftType.IsAnyOf("int", "bool", "float", "complex"))
emitter.EmitBox(emitter.ResolveType(leftType));
var method = typeof(MirelleStdlib.ArrayHelper).GetMethod("Has", new[] { typeof(object), typeof(object) });
emitter.EmitCall(emitter.AssemblyImport(method));
}
// an object has a "has" method that accepts the lefthand expression
else
{
try
{
Expr.IdentifierInvoke("has", Right, Left).Compile(emitter);
return;
}
catch { }
Error(String.Format(Resources.errOperatorTypesMismatch, "in", leftType, rightType));
}
}
示例2: Compile
public override void Compile(Emitter.Emitter emitter)
{
var args = new[] { Parameters.Count == 1 ? typeof(object) : typeof(IEnumerable<dynamic>), typeof(bool) };
var printMethod = emitter.AssemblyImport(typeof(MirelleStdlib.Printer).GetMethod("Print", args));
if (Parameters.Count == 1)
{
var currType = Parameters[0].GetExpressionType(emitter);
Parameters[0].Compile(emitter);
if (currType.IsAnyOf("int", "bool", "float", "complex"))
emitter.EmitBox(emitter.ResolveType(currType));
}
else
{
var objType = emitter.AssemblyImport(typeof(object));
var arrType = new ArrayType(objType);
var tmpVariable = emitter.CurrentMethod.Scope.Introduce("object[]", arrType);
// load count & create
emitter.EmitLoadInt(Parameters.Count);
emitter.EmitNewArray(objType);
emitter.EmitSaveVariable(tmpVariable);
int idx = 0;
foreach (var curr in Parameters)
{
var currType = curr.GetExpressionType(emitter);
emitter.EmitLoadVariable(tmpVariable);
emitter.EmitLoadInt(idx);
curr.Compile(emitter);
if (currType.IsAnyOf("int", "bool", "float", "complex"))
emitter.EmitBox(emitter.ResolveType(currType));
emitter.EmitSaveIndex("object");
idx++;
}
// return the created array
emitter.EmitLoadVariable(tmpVariable);
}
emitter.EmitLoadBool(PrintLine);
emitter.EmitCall(printMethod);
}