public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value != null) { switch (Type.GetTypeCode(value.GetType())) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Decimal: case TypeCode.Single: case TypeCode.Double: return(new SexagesimalAngle((double)value)); case TypeCode.String: return(SexagesimalAngle.Parse((string)value)); case TypeCode.Object: if (value.GetType() == typeof(SexagesimalAngle)) { return(value); } break; } } return(base.ConvertFrom(context, culture, value)); }
public override bool IsValid(ITypeDescriptorContext context, object value) { if (value != null) { switch (Type.GetTypeCode(value.GetType())) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Decimal: decimal decValue = (decimal)value; return(decValue > (decimal) - SexagesimalAngle.MaxTotalDegrees && decValue < (decimal)SexagesimalAngle.MaxTotalDegrees); case TypeCode.Single: case TypeCode.Double: double dblValue = (double)value; return(dblValue > (double)-SexagesimalAngle.MaxTotalDegrees && dblValue < (double)SexagesimalAngle.MaxTotalDegrees); case TypeCode.String: SexagesimalAngle result; return(SexagesimalAngle.TryParse((string)value, out result)); case TypeCode.Object: if (value.GetType() == typeof(SexagesimalAngle)) { return(true); } break; } } return(false); }
public static bool TryParse(string s, IFormatProvider provider, out SexagesimalAngle result) { if (provider == null) { provider = CultureInfo.CurrentCulture; } NumberFormatInfo nfi = (NumberFormatInfo)provider.GetFormat(typeof(NumberFormatInfo)); string pattern = string.Format(PatternFormat, nfi.NumberDecimalSeparator); Match match = Regex.Match(s, pattern); if (match.Success) { int degree = string.IsNullOrEmpty(match.Groups["degree"].Value) ? 0 : int.Parse(match.Groups["degree"].Value); int minute = string.IsNullOrEmpty(match.Groups["minute"].Value) ? 0 : int.Parse(match.Groups["minute"].Value); int second = string.IsNullOrEmpty(match.Groups["second"].Value) ? 0 : int.Parse(match.Groups["second"].Value); int hundredth = string.IsNullOrEmpty(match.Groups["hundredth"].Value) ? 0 : int.Parse(match.Groups["hundredth"].Value); bool negative = match.Groups["sign"].Value == "-"; result = new SexagesimalAngle(degree, minute, second, hundredth, negative); return(true); } else { pattern = string.Format(NumericPattern, nfi.NumberDecimalSeparator); match = Regex.Match(s, pattern); if (match.Success) { double angle; if (match.Groups["degree"].Success && double.TryParse(match.Groups["angle"].Value, NumberStyles.Float, provider, out angle)) { result = new SexagesimalAngle(angle); return(true); } else if (match.Groups["radian"].Success && double.TryParse(match.Groups["angle"].Value, NumberStyles.Float, provider, out angle)) { result = SexagesimalAngle.FromRadian(angle); return(true); } } } result = new SexagesimalAngle(); return(false); }
public static bool TryParse(string s, out SexagesimalAngle result) { return(TryParse(s, null, out result)); }
public SexagesimalAngle Subtract(SexagesimalAngle op) { return(new SexagesimalAngle((int)(((long)this._units - (long)op._units) % (long)MaxTotalUnits))); }