public static void EmitConversion(this ILGenerator iLGenerator, Type to, Type from) { switch (Type.GetTypeCode(to)) { case TypeCode.Decimal: iLGenerator.Emit(OpCodes.Box, typeof(decimal)); break; case TypeCode.Int32: iLGenerator.Emit(OpCodes.Conv_I4); break; case TypeCode.UInt32: iLGenerator.Emit(OpCodes.Conv_U4); break; case TypeCode.Int64: iLGenerator.Emit(OpCodes.Conv_I8); break; case TypeCode.UInt64: iLGenerator.Emit(OpCodes.Conv_U8); break; case TypeCode.Single: if (from.IsUnsigned()) { iLGenerator.Emit(OpCodes.Conv_R_Un); } iLGenerator.Emit(OpCodes.Conv_R4); break; case TypeCode.Double: if (from.IsUnsigned()) { iLGenerator.Emit(OpCodes.Conv_R_Un); } iLGenerator.Emit(OpCodes.Conv_R8); return; } }
public bool GetSimpleValue(IJavascriptObject decoratedValue, out object res, Type iTargetType = null) { res = null; var value = decoratedValue.Convert(); if ((value.IsUndefined) || (value.IsNull)) { return true; } if (value.IsString) { res = value.StringValue; return true; } if (value.IsBool) { res = value.BoolValue; return true; } if (iTargetType.IsUnsigned()) { if (value.IsUint) res = value.UintValue; } else { if (value.IsInt) res = value.IntValue; } if ((res == null) && (value.IsDouble)) { res = value.DoubleValue; } if (res != null) { if (iTargetType != null) res = Convert.ChangeType(res, iTargetType); return true; } if (value.IsDate) { res = value.DateValue.ToUniversalTime(value.DateValue); return true; } return false; }
public bool GetSimpleValue(IJavascriptObject ijsvalue, out object res, Type iTargetType = null) { res = null; CefV8Value value = CefV8_JavascriptObject.Convert(ijsvalue); if ((value.IsUndefined) || (value.IsNull)) { return true; } if (value.IsString) { res = ijsvalue.GetStringValue(); return true; } if (value.IsBool) { res = value.GetBoolValue(); return true; } if (iTargetType.IsUnsigned()) { if (value.IsUInt) res = value.GetUIntValue(); } else { if (value.IsInt) res = value.GetIntValue(); } if ((res == null) && (value.IsDouble)) { res = value.GetDoubleValue(); } if (res != null) { if (iTargetType != null) res = Convert.ChangeType(res, iTargetType); return true; } if (value.IsDate) { res = value.GetDateValue(); return true; } return false; }
private static void EmitUnsignedByType(this ILGenerator ILGenerator, OpCode signedOpCode, OpCode unsignedOpCode, Type type) { if (type.IsUnsigned()) { ILGenerator.Emit(unsignedOpCode); } else { ILGenerator.Emit(signedOpCode); } }
private static void EmitPostIncrement_Decreament(this ILGenerator ILGenerator, OpCode signedOpCode, OpCode unsignedOverflowOpCode, OpCode signedOverflowOpCode, Type type, bool isChecked) { ILGenerator.Emit(OpCodes.Dup); ILGenerator.Emit(OpCodes.Ldc_I4_1); if (isChecked) { if (type.IsUnsigned()) { ILGenerator.Emit(unsignedOverflowOpCode); } else if (type.IsFloatingPoint()) { ILGenerator.Emit(signedOpCode); } else { ILGenerator.Emit(signedOverflowOpCode); } } else { ILGenerator.Emit(signedOpCode); } }
private static void EmitPossiblyOverflowOperation(this ILGenerator ILGenerator, OpCode signedOpCode, OpCode unsignedOverflowOpCode, OpCode signedOverflowOpCode, Type leftType, Type rightType, bool isChecked) { if (isChecked) { if (leftType.IsUnsigned() && rightType.IsUnsigned()) { ILGenerator.Emit(unsignedOverflowOpCode); } else if (leftType.IsFloatingPoint() || rightType.IsFloatingPoint()) { ILGenerator.Emit(signedOpCode); } else { ILGenerator.Emit(signedOverflowOpCode); } } else { ILGenerator.Emit(signedOpCode); } }
private static void EmitGreater_LessThanOrEqual(this ILGenerator ILGenerator, OpCode signedOpCode, OpCode unsignedOpCode, Type leftType, Type rightType) { if ((leftType.IsUnsigned() && rightType.IsUnsigned()) || leftType.IsFloatingPoint()) { ILGenerator.Emit(unsignedOpCode); } else { ILGenerator.Emit(signedOpCode); } ILGenerator.Emit(OpCodes.Ldc_I4_0); ILGenerator.Emit(OpCodes.Ceq); }
internal static void EmitConversion(this ILGenerator ILGenerator, Type to, Type from) { switch (Type.GetTypeCode(to)) { case TypeCode.Decimal: ILGenerator.Emit(OpCodes.Box, TypeSystem.Decimal); break; case TypeCode.Int32: ILGenerator.Emit(OpCodes.Conv_I4); break; case TypeCode.UInt32: ILGenerator.Emit(OpCodes.Conv_U4); break; case TypeCode.Int64: ILGenerator.Emit(OpCodes.Conv_I8); break; case TypeCode.UInt64: ILGenerator.Emit(OpCodes.Conv_U8); break; case TypeCode.Single: if (from.IsUnsigned()) { ILGenerator.Emit(OpCodes.Conv_R_Un); } ILGenerator.Emit(OpCodes.Conv_R4); break; case TypeCode.Double: if (from.IsUnsigned()) { ILGenerator.Emit(OpCodes.Conv_R_Un); } ILGenerator.Emit(OpCodes.Conv_R8); return; } }
public void IsUnsigned_returns_expected_value(Type type, bool result) { var isUnsigned = type.IsUnsigned(); isUnsigned.Should().Be(result); }