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 HourAngle((double)value)); case TypeCode.String: return(HourAngle.Parse((string)value)); case TypeCode.Object: if (value.GetType() == typeof(HourAngle)) { 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) - HourAngle.MaxTotalHours && decValue < (decimal)HourAngle.MaxTotalHours); case TypeCode.Single: case TypeCode.Double: double dblValue = (double)value; return(dblValue > (double)-HourAngle.MaxTotalHours && dblValue < (double)HourAngle.MaxTotalHours); case TypeCode.String: HourAngle result; return(HourAngle.TryParse((string)value, out result)); case TypeCode.Object: if (value.GetType() == typeof(HourAngle)) { return(true); } break; } } return(false); }
public static bool TryParse(string s, IFormatProvider provider, out HourAngle 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["hour"].Value) ? 0 : int.Parse(match.Groups["hour"].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 isNegative = match.Groups["sign"].Value == "-"; result = (isNegative) ? new HourAngle(-degree, -minute, -second, -hundredth) : new HourAngle(degree, minute, second, hundredth); return(true); } else { pattern = string.Format(NumericPattern, nfi.NumberDecimalSeparator); match = Regex.Match(s, pattern); if (match.Success) { double angle; if (match.Groups["hour"].Success && double.TryParse(match.Groups["angle"].Value, NumberStyles.Float, provider, out angle)) { result = new HourAngle(angle); return(true); } else if (match.Groups["radian"].Success && double.TryParse(match.Groups["angle"].Value, NumberStyles.Float, provider, out angle)) { result = HourAngle.FromRadian(angle); return(true); } } } result = new HourAngle(); return(false); }
public static bool TryParse(string s, out HourAngle result) { return(TryParse(s, null, out result)); }
public HourAngle Subtract(HourAngle op) { return(new HourAngle((int)(((long)this._units - (long)op._units) % (long)MaxTotalUnits))); }
public HourAngle Add(HourAngle op) { return(new HourAngle((int)(((long)this._units + (long)op._units) % (long)MaxTotalUnits))); }