public Int8 ToInt8() { switch (Object) { case Int8 __sb: return((Int8)__sb); case Int16 _ss: return((Int8)_ss); case Int32 _si: return((Int8)_si); case Int64 _sl: return((Int8)_sl); case UInt8 _ub: return((Int8)_ub); case UInt16 us: return((Int8)us); case UInt32 ui: return((Int8)ui); case UInt64 ul: return((Int8)ul); case String __s: return(Int8.Parse(__s)); } throw new Exception($"Not sure how to convert '{Object}' into an Int8"); }
public void UpdateFromConfiguration(string value) { var m = Regex.Match(value, @"^\s*(-?\s*\d+)\s+(\w+)\s*$"); switch (m.Groups[2].Value) { case "slashing": Slashing = BaseType.Parse(m.Groups[1].Value); break; case "crushing": Crushing = BaseType.Parse(m.Groups[1].Value); break; case "fire": Fire = BaseType.Parse(m.Groups[1].Value); break; case "shadow": Shadow = BaseType.Parse(m.Groups[1].Value); break; default: throw new InvalidOperationException(); } }
public static bool TryParse(string data, DataType flag, out SimpleType value) { try { switch (flag) { case DataType.Null: value = new SimpleType(null); break; case DataType.Bool: value = new SimpleType(Boolean.Parse(data)); break; case DataType.Char: value = new SimpleType(Char.Parse(data)); break; case DataType.Byte: value = new SimpleType(Byte.Parse(data)); break; case DataType.SByte: value = new SimpleType(SByte.Parse(data)); break; case DataType.Short: value = new SimpleType(Int16.Parse(data)); break; case DataType.UShort: value = new SimpleType(UInt16.Parse(data)); break; case DataType.Int: value = new SimpleType(Int32.Parse(data)); break; case DataType.UInt: value = new SimpleType(UInt32.Parse(data)); break; case DataType.Long: value = new SimpleType(Int64.Parse(data)); break; case DataType.ULong: value = new SimpleType(UInt64.Parse(data)); break; case DataType.Float: value = new SimpleType(Single.Parse(data)); break; case DataType.Decimal: value = new SimpleType(Decimal.Parse(data)); break; case DataType.Double: value = new SimpleType(Double.Parse(data)); break; case DataType.String: value = new SimpleType(data); break; case DataType.DateTime: value = new SimpleType(DateTime.Parse(data)); break; case DataType.TimeSpan: value = new SimpleType(TimeSpan.Parse(data)); break; default: value = new SimpleType(null); break; } return(true); } catch { value = new SimpleType(null); return(false); } }
public static bool TryConvert(string data, DataType flag, out object val) { val = null; if (flag == DataType.Null) { return(false); } try { var numStyle = Insensitive.StartsWith(data.Trim(), "0x") ? NumberStyles.HexNumber : NumberStyles.Any; if (numStyle == NumberStyles.HexNumber) { data = data.Substring(data.IndexOf("0x", StringComparison.OrdinalIgnoreCase) + 2); } switch (flag) { case DataType.Bool: val = Boolean.Parse(data); return(true); case DataType.Char: val = Char.Parse(data); return(true); case DataType.Byte: val = Byte.Parse(data, numStyle); return(true); case DataType.SByte: val = SByte.Parse(data, numStyle); return(true); case DataType.Short: val = Int16.Parse(data, numStyle); return(true); case DataType.UShort: val = UInt16.Parse(data, numStyle); return(true); case DataType.Int: val = Int32.Parse(data, numStyle); return(true); case DataType.UInt: val = UInt32.Parse(data, numStyle); return(true); case DataType.Long: val = Int64.Parse(data, numStyle); return(true); case DataType.ULong: val = UInt64.Parse(data, numStyle); return(true); case DataType.Float: val = Single.Parse(data, numStyle); return(true); case DataType.Decimal: val = Decimal.Parse(data, numStyle); return(true); case DataType.Double: val = Double.Parse(data, numStyle); return(true); case DataType.String: val = data; return(true); case DataType.DateTime: val = DateTime.Parse(data, CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces); return(true); case DataType.TimeSpan: val = TimeSpan.Parse(data); return(true); default: return(false); } } catch { return(false); } }