本文整理汇总了C#中Dot42.CompilerLib.XModel.XTypeReference.GetBoxValueOfMethod方法的典型用法代码示例。如果您正苦于以下问题:C# XTypeReference.GetBoxValueOfMethod方法的具体用法?C# XTypeReference.GetBoxValueOfMethod怎么用?C# XTypeReference.GetBoxValueOfMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dot42.CompilerLib.XModel.XTypeReference
的用法示例。
在下文中一共展示了XTypeReference.GetBoxValueOfMethod方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Box
/// <summary>
/// Create code to box the given source value into the given type.
/// </summary>
public static RLRange Box(this IRLBuilder builder, ISourceLocation sequencePoint, RegisterSpec source, XTypeReference type, DexTargetPackage targetPackage, IRegisterAllocator frame)
{
if (type.IsPrimitive)
{
if (type.IsByte()) builder.Add(sequencePoint, RCode.Int_to_byte, source.Register, source.Register);
else if (type.IsUInt16()) builder.Add(sequencePoint, RCode.Int_to_short, source.Register, source.Register);
// Call appropriate valueOf method
var boxedType = type.Module.TypeSystem.Object;
var r = frame.AllocateTemp(boxedType.GetReference(targetPackage));
var call = builder.Add(sequencePoint, RCode.Invoke_static, type.GetBoxValueOfMethod(), source.Registers);
var last = builder.Add(sequencePoint, RCode.Move_result_object, r);
return new RLRange(call, last, r);
}
if (type.IsGenericParameter)
{
var nop = builder.Add(sequencePoint, RCode.Nop);
return new RLRange(nop, source);
}
XTypeDefinition typeDef ;
if (type.TryResolve(out typeDef) && (typeDef.IsEnum))
{
// Call appropriate valueOf method
/*var boxedType = type.Module.TypeSystem.Object;
var r = frame.AllocateTemp(boxedType.GetReference(target, nsConverter));
var call = builder.Add(sequencePoint, RCode.Invoke_static, typeDef.GetEnumUnderlyingType().GetBoxValueOfMethod(), source.Registers);
var last = builder.Add(sequencePoint, RCode.Move_result_object, r);
return new RLRange(call, last, r);*/
}
// Just cast
var checkCast = builder.Add(sequencePoint, RCode.Check_cast, type.GetReference(targetPackage), source);
return new RLRange(checkCast, source);
}