public static uint ConvertToUInt (CallSite site, object o) { #if BINDERS_RUNTIME_STATS Stats.Increment(StatsCounter.ConvertBinderInvoked); #endif if (o is uint) { return (uint)o; } if (o is int) { return (uint)(int)o; } if (o == null || o == PlayScript.Undefined._undefined) { return 0; } var typeCode = Type.GetTypeCode (o.GetType ()); switch (typeCode) { case TypeCode.Int32: return (uint)((int)o); case TypeCode.Double: return (uint)((double)o); case TypeCode.Boolean: return (bool)o ? (uint)1 : (uint)0; case TypeCode.UInt32: return (uint)o; case TypeCode.Single: return (uint)((float)o); case TypeCode.String: return uint.Parse((String)o); default: throw new Exception ("Invalid cast to int"); } }
private static bool IsEvent(CallSite site, object o) { #if BINDERS_RUNTIME_STATS Stats.Increment(StatsCounter.IsEventBinderInvoked); #endif // $$TODO return false; }
public static int ConvertToInt (CallSite site, object o) { #if BINDERS_RUNTIME_STATS Stats.Increment(StatsCounter.ConvertBinderInvoked); #endif if (o is int) { return (int)o; } if (o is uint) { return (int)(uint)o; } if (o == null || o == PlayScript.Undefined._undefined) { return 0; } var typeCode = Type.GetTypeCode (o.GetType ()); switch (typeCode) { case TypeCode.Int32: return (int)o; case TypeCode.Double: return (int)((double)o); case TypeCode.Boolean: return (bool)o ? 1 : 0; case TypeCode.UInt32: return (int)((uint)o); case TypeCode.Single: return (int)((float)o); case TypeCode.String: { string s =(string)o; if (s.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase)) { // Hex number - Use Convert.ToInt32() so we don't have to strip "0x" from the string. return Convert.ToInt32(s, 16); } else { return int.Parse(s); } } default: throw new Exception ("Invalid cast to int"); } }
public static object ConvertToObj (CallSite site, object o) { #if BINDERS_RUNTIME_STATS Stats.Increment(StatsCounter.ConvertBinderInvoked); #endif return o; }
public static string ConvertToString (CallSite site, object o) { #if BINDERS_RUNTIME_STATS Stats.Increment(StatsCounter.ConvertBinderInvoked); #endif if (o == null || o == PlayScript.Undefined._undefined) { return null; } else if (o is string) { return (string)o; } else { return o.ToString (); } }
public static bool ConvertToBool (CallSite site, object o) { #if BINDERS_RUNTIME_STATS Stats.Increment(StatsCounter.ConvertBinderInvoked); #endif if (o is bool) { return (bool)o; } if (o == null || o == PlayScript.Undefined._undefined) { return false; } var typeCode = Type.GetTypeCode (o.GetType ()); switch (typeCode) { case TypeCode.Int32: return (int)o != 0; case TypeCode.Double: return (double)o != 0.0; case TypeCode.Boolean: return (bool)o; case TypeCode.UInt32: return (uint)o != 0; case TypeCode.Single: return (float)o != 0.0f; default: throw new Exception ("Invalid cast to int"); } }
public static object ConvertToObj (CallSite site, object o) { return o; }
public static string ConvertToString (CallSite site, object o) { if (o == null || o == PlayScript.Undefined._undefined) { return null; } else if (o is string) { return (string)o; } else { return o.ToString (); } }
public static bool ConvertToBool (CallSite site, object o) { if (o is bool) { return (bool)o; } if (o == null || o == PlayScript.Undefined._undefined) { return false; } var typeCode = Type.GetTypeCode (o.GetType ()); switch (typeCode) { case TypeCode.Int32: return (int)o != 0; case TypeCode.Double: return (double)o != 0.0; case TypeCode.Boolean: return (bool)o; case TypeCode.UInt32: return (uint)o != 0; case TypeCode.Single: return (float)o != 0.0f; default: throw new Exception ("Invalid cast to int"); } }
public static double ConvertToDouble (CallSite site, object o) { if (o is double) { return (double)o; } if (o is float) { return (double)(float)o; } if (o == null || o == PlayScript.Undefined._undefined) { return 0.0; } var typeCode = Type.GetTypeCode (o.GetType ()); switch (typeCode) { case TypeCode.Int32: return (int)o; case TypeCode.Double: return (double)o; case TypeCode.Boolean: return (bool)o ? 1 : 0; case TypeCode.UInt32: return (uint)o; case TypeCode.Single: return (float)o; case TypeCode.String: return double.Parse((String)o); default: throw new Exception ("Invalid cast to double"); } }
private static bool IsEvent(CallSite site, object o) { // $$TODO return false; }