コード例 #1
0
        public static NumberErrorCause TryParse(string str, NumberRange range, out double value)
        {
            var cause = NumberErrorCause.None;
            var parse = str.ToDoubleNullableGeneal();

            value = parse ?? 0.0D;

            if (parse.HasValue == false)
            {
                cause = NumberErrorCause.Invalid;
            }
            else if (range != null)
            {
                int dotIndex = str.IndexOf(".");

                if (dotIndex > -1 && str.Substring(dotIndex + 1).Length > range.Dps)
                {
                    cause = NumberErrorCause.DpsOver;
                }
                else if (CheckMin(value, range) == false)
                {
                    cause = NumberErrorCause.MinOver;
                }
                else if (CheckMax(value, range) == false)
                {
                    cause = NumberErrorCause.MaxOver;
                }
            }

            return(cause);
        }
コード例 #2
0
 public void SetNumberRange(NumberRange range)
 {
     this.Type = KeypadType.Number;
     this.Min  = range.Min;
     this.Max  = range.Max;
     this.Dps  = range.Dps;
 }
コード例 #3
0
        public KeypadParseResult Validate(string text)
        {
            var result = new KeypadParseResult();
            var type   = this.Type;

            if (type == KeypadType.Number)
            {
                var cause = NumberRange.TryParse(text, this.ToNumberRange(), out var value);
                result.NumberErrorCause = cause;
                result.Number           = value;
                result.Validated        = cause == NumberErrorCause.None;
            }
            else if (type == KeypadType.IPAddress)
            {
                IPAddress value  = null;
                var       cause  = IPAddressErrorCause.None;
                var       splits = text.Split('.');

                if (splits.Length == 4)
                {
                    var anyDecimalValidated = splits.All(t => { return(byte.TryParse(t, out var b)); });

                    if (anyDecimalValidated == true)
                    {
                        if (IPAddress.TryParse(text, out value) == false)
                        {
                            cause = IPAddressErrorCause.ParseError;
                        }
                    }
                    else
                    {
                        cause = IPAddressErrorCause.AnyDecimalInvalid;
                    }
                }
                else
                {
                    cause = IPAddressErrorCause.DecimalCountInvalid;
                }

                result.Validated      = cause == IPAddressErrorCause.None;
                result.IPAddressCause = cause;
                result.IPAddress      = value;
            }
            else if (type == KeypadType.String)
            {
                result.Validated = true;
                result.String    = text;
            }

            var e = new KeypadValidateEventArgs(this, result, text);

            this.OnValidate(e);
            return(result);
        }
コード例 #4
0
 public static bool CheckMax(double value, NumberRange range)
 {
     return(CheckMax(value, range.Max));
 }
コード例 #5
0
 public static bool CheckMin(double value, NumberRange range)
 {
     return(CheckMin(value, range.Min));
 }
コード例 #6
0
 public NumberRange(NumberRange other)
 {
     this.Min = other.Min;
     this.Max = other.Max;
     this.Dps = other.Dps;
 }