예제 #1
0
        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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 public static bool TryParse(string s, out HourAngle result)
 {
     return(TryParse(s, null, out result));
 }
예제 #5
0
 public HourAngle Subtract(HourAngle op)
 {
     return(new HourAngle((int)(((long)this._units - (long)op._units) % (long)MaxTotalUnits)));
 }
예제 #6
0
 public HourAngle Add(HourAngle op)
 {
     return(new HourAngle((int)(((long)this._units + (long)op._units) % (long)MaxTotalUnits)));
 }