本文整理汇总了C#中CodeGen.EmitUnbox方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGen.EmitUnbox方法的具体用法?C# CodeGen.EmitUnbox怎么用?C# CodeGen.EmitUnbox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGen
的用法示例。
在下文中一共展示了CodeGen.EmitUnbox方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
public override void Emit(CodeGen cg) {
// RuntimeHelpers.LookupName(CodeContext, name)
cg.EmitCodeContext();
cg.EmitSymbolId(_name);
cg.EmitUnbox(typeof(SymbolId));
cg.EmitCall(typeof(RuntimeHelpers), "LookupName");
}
示例2: EmitCheck
public virtual void EmitCheck(CodeGen cg, SymbolId name)
{
Contract.RequiresNotNull(cg, "cg");
Label endCheck = cg.DefineLabel();
cg.Emit(OpCodes.Dup);
cg.EmitUninitialized();
cg.Emit(OpCodes.Bne_Un_S, endCheck);
if (_local) {
cg.EmitSymbolId(name);
cg.EmitUnbox(typeof(SymbolId));
cg.EmitCall(typeof(RuntimeHelpers), "ThrowUnboundLocalError");
} else {
cg.Emit(OpCodes.Pop);
cg.EmitCodeContext();
cg.EmitSymbolId(name);
cg.EmitUnbox(typeof(SymbolId));
cg.EmitCall(typeof(RuntimeHelpers), "LookupName");
}
cg.MarkLabel(endCheck);
}
示例3: EmitOnYieldBranchToLabel
private void EmitOnYieldBranchToLabel(List<YieldTarget> yieldTargets, Slot isYielded, Label label, CodeGen cg)
{
if (IsBlockYieldable(yieldTargets)) {
isYielded.EmitGet(cg);
cg.EmitUnbox(typeof(bool));
cg.Emit(OpCodes.Brtrue, label);
}
}
示例4: Emit
//.........这里部分代码省略.........
}
Slot exception = null;
bool foundLoopControl;
bool returnInFinally = ControlFlowFinder.FindControlFlow(FinallyStatement, out foundLoopControl);
if (IsBlockYieldable(finallyYieldTargets)) {
exception = cg.Names.GetTempSlot("exception", typeof(Exception));
cg.Emit(OpCodes.Ldnull);
exception.EmitSet(cg);
} else if (returnInFinally) {
exception = cg.GetLocalTmp(typeof(Exception));
cg.Emit(OpCodes.Ldnull);
exception.EmitSet(cg);
}
EmitTopYieldTargetLabels(tryYieldTargets, tryChoiceVar, cg);
EmitTopYieldTargetLabels(catchYieldTargets, catchChoiceVar, cg);
EmitTopYieldTargetLabels(elseYieldTargets, elseChoiceVar, cg);
EmitTopYieldTargetLabels(finallyYieldTargets, finallyChoiceVar, cg);
cg.EmitInt(CodeGen.FinallyExitsNormally);
flowControlVar.EmitSet(cg);
Label afterFinally = cg.DefineLabel();
cg.PushExceptionBlock(Targets.TargetBlockType.Try, flowControlVar, isTryYielded);
cg.BeginExceptionBlock();
// if catch yielded, rethow the storedException to be handled by Catch block
if (IsBlockYieldable(catchYieldTargets)) {
Label testFinally = cg.DefineLabel();
isCatchYielded.EmitGet(cg);
cg.EmitUnbox(typeof(bool));
cg.Emit(OpCodes.Brfalse, testFinally);
storedException.EmitGet(cg);
cg.EmitCall(typeof(Ops), "Raise", new Type[] { typeof(object) });
cg.MarkLabel(testFinally);
}
// if Finally yielded, Branch to the end of Try block
Label endOfTry = cg.DefineLabel();
EmitOnYieldBranchToLabel(finallyYieldTargets, isFinallyYielded, endOfTry, cg);
Label beginElseBlock = cg.DefineLabel();
if (IsBlockYieldable(elseYieldTargets)) {
// isElseYielded ?
Debug.Assert(isElseYielded != null);
isElseYielded.EmitGet(cg);
cg.EmitUnbox(typeof(bool));
cg.Emit(OpCodes.Brtrue, beginElseBlock);
}
EmitYieldDispatch(tryYieldTargets, isTryYielded, tryChoiceVar, cg);
// if finally block presents, but no exception handler, we add try-fault
// to update traceback; otherwise, we update the traceback inside exception handler.
if (finallyStmt != null && handlers == null) {
Slot dummySlot = cg.GetLocalTmp(typeof(object));
cg.EmitTraceBackTryBlockStart(dummySlot);
body.Emit(cg);
cg.FreeLocalTmp(dummySlot);
cg.EmitTraceBackFaultBlock();
} else {
示例5: EmitGetAs
public void EmitGetAs(CodeGen cg, Type asType)
{
Contract.RequiresNotNull(cg, "cg");
Contract.RequiresNotNull(asType, "asType");
EmitGet(cg);
if (asType == typeof(object) && this.Type.IsValueType) {
cg.EmitBoxing(this.Type);
return;
}
if (asType.IsAssignableFrom(this.Type)) {
return;
}
if (asType.IsAssignableFrom(_knownType)) {
cg.EmitUnbox(asType);
} else {
// A special case for int-> double until we can do the proper matrix
if (asType == typeof(double)) {
if (this.Type == typeof(int)) {
cg.Emit(OpCodes.Conv_R8);
return;
} else if (this.KnownType == typeof(int)) {
cg.EmitUnbox(typeof(int));
cg.Emit(OpCodes.Conv_R8);
return;
}
}
if (this.Type != typeof(object)) {
// TODO make this efficient, for now just go to object and back
//throw new InvalidOperationException();
cg.EmitBoxing(this.Type);
}
cg.EmitConvertFromObject(asType);
}
}