public static bool isInt(object obj) { System.IConvertible cv1 = obj as System.IConvertible; if (cv1 != null) { switch (cv1.GetTypeCode()) { case System.TypeCode.Double: double d = (double)obj; return(d >= int.MinValue && d <= int.MaxValue && d == ((int)d)); case System.TypeCode.UInt32: case System.TypeCode.Int32: return(true); default: return(false); } } return(false); }
public static bool eq(object v1, object v2) { if (System.Object.ReferenceEquals(v1, v2)) { return(true); } if (v1 == null || v2 == null) { return(false); } System.IConvertible v1c = v1 as System.IConvertible; if (v1c != null) { System.IConvertible v2c = v2 as System.IConvertible; if (v2c == null) { return(false); } System.TypeCode t1 = v1c.GetTypeCode(); System.TypeCode t2 = v2c.GetTypeCode(); if (t1 == t2) { return(v1c.Equals(v2c)); } switch (t1) { case System.TypeCode.Int64: case System.TypeCode.UInt64: return(v1c.ToUInt64(null) == v2c.ToUInt64(null)); default: return(v1c.ToDouble(null) == v2c.ToDouble(null)); } } System.ValueType v1v = v1 as System.ValueType; if (v1v != null) { return(v1.Equals(v2)); } else { System.Type v1t = v1 as System.Type; if (v1t != null) { System.Type v2t = v2 as System.Type; if (v2t != null) { return(typeEq(v1t, v2t)); } return(false); } } return(false); }
public static int compare(object v1, object v2) { if (v1 == v2) { return(0); } if (v1 == null) { return(-1); } if (v2 == null) { return(1); } System.IConvertible cv1 = v1 as System.IConvertible; if (cv1 != null) { System.IConvertible cv2 = v2 as System.IConvertible; if (cv2 == null) { throw new System.ArgumentException("Cannot compare " + v1.GetType().ToString() + " and " + v2.GetType().ToString()); } switch (cv1.GetTypeCode()) { case System.TypeCode.String: if (cv2.GetTypeCode() != System.TypeCode.String) { throw new System.ArgumentException("Cannot compare " + v1.GetType().ToString() + " and " + v2.GetType().ToString()); } string s1 = v1 as string; string s2 = v2 as string; int i = 0; int l1 = s1.Length; int l2 = s2.Length; bool active = true; while (active) { char h1; char h2; if (i >= l1) { h1 = (char)0; active = false; } else { h1 = s1[i]; } if (i >= l2) { h2 = (char)0; active = false; } else { h2 = s2[i]; } int v = h1 - h2; if (v > 0) { return(1); } else if (v < 0) { return(-1); } i++; } return(0); case System.TypeCode.Double: double d1 = (double)v1; double d2 = cv2.ToDouble(null); return((d1 < d2) ? -1 : (d1 > d2) ? 1 : 0); default: double d1d = cv1.ToDouble(null); double d2d = cv2.ToDouble(null); return((d1d < d2d) ? -1 : (d1d > d2d) ? 1 : 0); } } System.IComparable c1 = v1 as System.IComparable; System.IComparable c2 = v2 as System.IComparable; if (c1 == null || c2 == null) { if (c1 == c2) { return(0); } throw new System.ArgumentException("Cannot compare " + v1.GetType().ToString() + " and " + v2.GetType().ToString()); } return(c1.CompareTo(c2)); }
public static global::haxe.root.ValueType @typeof(object v) { if (v == null) { return(ValueType.TNull); } System.Type t = v as System.Type; if (t != null) { //class type return(ValueType.TObject); } t = v.GetType(); if (t.IsEnum) { return(ValueType.TEnum(t)); } if (t.IsValueType) { System.IConvertible vc = v as System.IConvertible; if (vc != null) { switch (vc.GetTypeCode()) { case System.TypeCode.Boolean: return(ValueType.TBool); case System.TypeCode.Double: double d = vc.ToDouble(null); if (d >= int.MinValue && d <= int.MaxValue && d == vc.ToInt32(null)) { return(ValueType.TInt); } else { return(ValueType.TFloat); } case System.TypeCode.Int32: return(ValueType.TInt); default: return(ValueType.TClass(t)); } } else { return(ValueType.TClass(t)); } } if (v is haxe.lang.IHxObject) { if (v is haxe.lang.DynamicObject) { return(ValueType.TObject); } else if (v is haxe.lang.Enum) { return(ValueType.TEnum(t)); } return(ValueType.TClass(t)); } else if (v is haxe.lang.Function) { return(ValueType.TFunction); } else { return(ValueType.TClass(t)); } }