public static System.IConvertible AddFlag(this System.IConvertible self, System.IConvertible flag) { int res = (int)self; res |= (int)flag; return(res); }
public BitTag(System.IConvertible flags, System.Type enumType) { LiteralValue = (ulong)flags.ToInt64(System.Globalization.CultureInfo.InvariantCulture); if (enumType == null || !enumType.IsEnum) { EnumType = null; } else { EnumType = enumType; } }
public static int GetFlagsCount(this System.IConvertible self) { var res = 0; var values = System.Enum.GetValues(self.GetType()); foreach (var value in values) { if (((int)self & (int)value) != 0) { res++; } } return(res); }
public string Get_string(System.IConvertible _arg_index) { int arg_index = _arg_index.ToInt32(null); if (arg_index < m_ArgList.Length) { return(m_ArgList[arg_index]); } if (arg_index < m_ArgDefault.Length) { return(m_ArgDefault[arg_index]); } throw new System.Exception("arg_index overflow : " + arg_index + " : " + m_sFormat); }
public static T toValue <T>(this Variant self, string key, T defautValue = default(T)) where T : System.IConvertible { Variant ret = self[key]; if (ret == null) { return(defautValue); } if (typeof(T).BaseType == typeof(System.Enum)) { return(ret.toEnum <T>()); } else { var typeCode = defautValue != null?defautValue.GetTypeCode() : System.TypeCode.String; System.IConvertible convertible = ret; switch (typeCode) { case System.TypeCode.Boolean: convertible = (System.Boolean)ret; break; case System.TypeCode.Single: convertible = (System.Single)ret; break; case System.TypeCode.Double: convertible = (System.Double)ret; break; case System.TypeCode.UInt16: convertible = (System.UInt16)ret; break; case System.TypeCode.Int16: convertible = (System.Int16)ret; break; case System.TypeCode.Int32: convertible = (System.Int32)ret; break; case System.TypeCode.UInt32: convertible = (System.UInt32)ret; break; case System.TypeCode.UInt64: convertible = (System.UInt64)ret; break; case System.TypeCode.Int64: convertible = (System.Int64)ret; break; case System.TypeCode.Decimal: convertible = (System.Decimal)ret; break; case System.TypeCode.String: convertible = (System.String)ret; break; default: return(defautValue); } return((T)convertible); } }
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 object plus(object v1, object v2) { if (v1 is string || v2 is string) { return(Std.@string(v1) + Std.@string(v2)); } 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 dynamically add " + v1.GetType().ToString() + " and " + v2.GetType().ToString()); } return(cv1.ToDouble(null) + cv2.ToDouble(null)); } throw new System.ArgumentException("Cannot dynamically add " + v1 + " and " + v2); }
public static System.IConvertible BitmapPopup(string p_label, System.IConvertible p_enum) { System.IConvertible p_return = p_enum; if (EnumHelper.CheckIfIsEnum(p_enum.GetType(), true)) { try { int v_value = (int)((System.IConvertible)p_enum); if (string.IsNullOrEmpty(p_label)) { v_value = EditorGUILayout.MaskField(v_value, System.Enum.GetNames(p_enum.GetType())); } else { v_value = EditorGUILayout.MaskField(p_label, v_value, System.Enum.GetNames(p_enum.GetType())); } p_return = ((System.IConvertible)v_value); } catch {} } else if (EnumHelper.CheckIfIsEnum(p_enum.GetType(), false)) { try { if (string.IsNullOrEmpty(p_label)) { p_return = (System.Enum)EditorGUILayout.EnumPopup((System.Enum)p_enum); } else { p_return = (System.Enum)EditorGUILayout.EnumPopup(p_label, (System.Enum)p_enum); } } catch {} } return(p_return); }
/// <summary> /// Construct the exception. /// </summary> /// <param name="wrong"> Value that is infinite or NaN. </param> /// <param name="args"> Optional arguments. </param> public NotFiniteNumberException(Number wrong, params object[] args) : this(LocalizedFormats.NOT_FINITE_NUMBER, wrong, args) { }
public BitTag(System.IConvertible flags) { LiteralValue = (ulong)flags.ToInt64(System.Globalization.CultureInfo.InvariantCulture); EnumType = null; }
public string this[System.IConvertible _arg_index] { get { return(Get_string(_arg_index)); } }
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 NumberIsTooLargeException(LocalizedFormats specific, Number wrong, Number max, bool boundIsAllowed) : base(specific, wrong, max) { this.max = max; this.boundIsAllowed = boundIsAllowed; }
public OutOfRangeException(LocalizedFormats specific, Number wrong, Number lo, Number hi) : base(specific, wrong, lo, hi) { this.lo = lo; this.hi = hi; }
/// <summary> /// Construct the exception. /// </summary> /// <param name="wrong"> Value that is smaller than the minimum. </param> /// <param name="min"> Minimum. </param> /// <param name="boundIsAllowed"> Whether {@code min} is included in the allowed range. </param> public NumberIsTooSmallException(Number wrong, Number min, bool boundIsAllowed) : this(boundIsAllowed ? LocalizedFormats.NUMBER_TOO_SMALL : LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED, wrong, min, boundIsAllowed) { }
/// <summary> /// Sets the <see cref="Declaration.DefaultValue"/> of the <see /// cref="Declaration"/>. /// </summary> /// <param name="defaultValue">The default value to apply to the /// Declaration.</param> /// <inheritdoc cref="WithName" path="/returns"/> public DeclarationBuilder WithDefaultValue(System.IConvertible defaultValue) { this.Declaration.DefaultValue = defaultValue; return(this); }
public NumberIsTooSmallException(LocalizedFormats specific, Number wrong, Number min, bool boundIsAllowed) : base(specific, wrong, min) { this.min = min; this.boundIsAllowed = boundIsAllowed; }
public static bool IsFlagOn(this System.IConvertible self, System.IConvertible flag) { return(((int)self & (int)flag) != 0); }
/// <summary> /// Construct the exception. /// </summary> /// <param name="max"> Maximum number of evaluations. </param> public TooManyIterationsException(Number max) : base(max) { GetContext().AddMessage(LocalizedFormats.ITERATIONS); }
public NotFiniteNumberException(LocalizedFormats specific, Number wrong, params object[] args) : base(specific, wrong, args) { }
public bool Has(System.IConvertible tag) { ulong otherLiteralValue = tag.ToUInt64(System.Globalization.CultureInfo.InvariantCulture); return((LiteralValue & otherLiteralValue) == otherLiteralValue); }
// called by various implementations of System.IConvertible.ToType [java.attr.Discard] extern public static object DefaultToType( System.IConvertible value, System.Type targetType, System.IFormatProvider provider);
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)); } }
/// <summary> /// Construct the exception. /// </summary> /// <param name="wrong"> Value that is larger than the maximum. </param> /// <param name="max"> Maximum. </param> /// <param name="boundIsAllowed"> if true the maximum is included in the allowed range. </param> public NumberIsTooLargeException(Number wrong, Number max, bool boundIsAllowed) : this(boundIsAllowed ? LocalizedFormats.NUMBER_TOO_LARGE : LocalizedFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED, wrong, max, boundIsAllowed) { }
/// <summary> /// Construct the exception. /// </summary> /// <param name="max"> Maximum. </param> public MaxCountExceededException(Number max) : this(LocalizedFormats.MAX_COUNT_EXCEEDED, max) { }
/// <summary> /// Construct an exception from the mismatched dimensions. /// </summary> /// <param name="wrong"> Requested value. </param> /// <param name="lo"> Lower bound. </param> /// <param name="hi"> Higher bound. </param> public OutOfRangeException(Number wrong, Number lo, Number hi) : this(LocalizedFormats.OUT_OF_RANGE_SIMPLE, wrong, lo, hi) { }
public MaxCountExceededException(LocalizedFormats specific, Number max, params object[] args) { GetContext().AddMessage(specific, max, args); this.max = max; }
/// <summary> /// Construct the exception. /// </summary> /// <param name="max"> Maximum number of evaluations. </param> public TooManyEvaluationsException(Number max) : base(max) { GetContext().AddMessage(LocalizedFormats.EVALUATIONS); }
public bool HasAny(System.IConvertible tag) { return((LiteralValue & tag.ToUInt64(System.Globalization.CultureInfo.InvariantCulture)) != 0UL); }