本文整理汇总了C#中Jurassic.Compiler.ILGenerator.ConvertUnsignedToDouble方法的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator.ConvertUnsignedToDouble方法的具体用法?C# ILGenerator.ConvertUnsignedToDouble怎么用?C# ILGenerator.ConvertUnsignedToDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jurassic.Compiler.ILGenerator
的用法示例。
在下文中一共展示了ILGenerator.ConvertUnsignedToDouble方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToNumber
/// <summary>
/// Pops the value on the stack, converts it to a double, then pushes the double result
/// onto the stack.
/// </summary>
/// <param name="generator"> The IL generator. </param>
/// <param name="fromType"> The type to convert from. </param>
public static void ToNumber(ILGenerator generator, PrimitiveType fromType)
{
// Check that a conversion is actually necessary.
if (fromType == PrimitiveType.Number)
return;
switch (fromType)
{
case PrimitiveType.Undefined:
// Converting from undefined produces NaN.
generator.Pop();
generator.LoadDouble(double.NaN);
break;
case PrimitiveType.Null:
// Converting from null produces 0.
generator.Pop();
generator.LoadDouble(0.0);
break;
case PrimitiveType.Bool:
// Converting from a boolean produces 0 if the boolean is false, or 1 if the boolean is true.
generator.ConvertToDouble();
break;
case PrimitiveType.Int32:
// Converting from int32 produces the same number.
generator.ConvertToDouble();
break;
case PrimitiveType.UInt32:
// Converting from a number produces the following:
generator.ConvertUnsignedToDouble();
break;
case PrimitiveType.String:
case PrimitiveType.ConcatenatedString:
case PrimitiveType.Any:
case PrimitiveType.Object:
// Otherwise, fall back to calling TypeConverter.ToNumber()
generator.Call(ReflectionHelpers.TypeConverter_ToNumber);
break;
default:
throw new NotImplementedException(string.Format("Unsupported primitive type: {0}", fromType));
}
}
示例2: EmitConversionToObject
//.........这里部分代码省略.........
if (fromType.IsValueType == false)
{
var startOfElse = generator.CreateLabel();
endOfNullCheck = generator.CreateLabel();
generator.Duplicate();
generator.BranchIfNotNull(startOfElse);
generator.Pop();
EmitHelpers.EmitNull(generator);
generator.Branch(endOfNullCheck);
generator.DefineLabelPosition(startOfElse);
}
switch (Type.GetTypeCode(fromType))
{
case TypeCode.Boolean:
generator.Box(typeof(bool));
break;
case TypeCode.Byte:
generator.Box(typeof(int));
break;
case TypeCode.Char:
generator.LoadInt32(1);
generator.NewObject(ReflectionHelpers.String_Constructor_Char_Int);
break;
case TypeCode.DBNull:
throw new NotSupportedException("DBNull is not a supported return type.");
case TypeCode.Decimal:
generator.Call(ReflectionHelpers.Decimal_ToDouble);
generator.Box(typeof(double));
break;
case TypeCode.Double:
generator.Box(typeof(double));
break;
case TypeCode.Empty:
throw new NotSupportedException("Empty is not a supported return type.");
case TypeCode.Int16:
generator.Box(typeof(int));
break;
case TypeCode.Int32:
generator.Box(typeof(int));
break;
case TypeCode.Int64:
generator.ConvertToDouble();
generator.Box(typeof(double));
break;
case TypeCode.DateTime:
case TypeCode.Object:
// Check if the type must be wrapped with a ClrInstanceWrapper.
// Note: if the type is a value type it cannot be a primitive or it would
// have been handled elsewhere in the switch.
ILLabel endOfWrapCheck = null;
if (fromType.IsValueType == false)
{
generator.Duplicate();
generator.Call(ReflectionHelpers.TypeUtilities_IsPrimitiveOrObject);
endOfWrapCheck = generator.CreateLabel();
generator.BranchIfTrue(endOfWrapCheck);
}
// The type must be wrapped.
var temp = generator.CreateTemporaryVariable(fromType);
generator.StoreVariable(temp);
generator.LoadArgument(0);
generator.LoadVariable(temp);
if (fromType.IsValueType == true)
generator.Box(fromType);
generator.ReleaseTemporaryVariable(temp);
generator.NewObject(ReflectionHelpers.ClrInstanceWrapper_Constructor);
// End of wrap check.
if (fromType.IsValueType == false)
generator.DefineLabelPosition(endOfWrapCheck);
break;
case TypeCode.SByte:
generator.Box(typeof(int));
break;
case TypeCode.Single:
generator.Box(typeof(double));
break;
case TypeCode.String:
break;
case TypeCode.UInt16:
generator.Box(typeof(int));
break;
case TypeCode.UInt32:
generator.Box(typeof(uint));
break;
case TypeCode.UInt64:
generator.ConvertUnsignedToDouble();
generator.Box(typeof(double));
break;
}
// Label the end of the null check.
if (fromType.IsValueType == false)
generator.DefineLabelPosition(endOfNullCheck);
}