示例#1
0
        public MudNumericField() : base()
        {
            //With input[type=number] the browser reads and sets the value using dot as decimal separator, while showing and parsing the text in the user Locale setting.
            //Since this is completely transparent to us, we need to use a Converter using an InvariantCulture.
            SetConverter(new DefaultConverter <T> {
                Culture = CultureInfo.InvariantCulture
            });

            _validateInstance = new Func <T, Task <bool> >(ValidateInput);
            _inputConverter   = new NumericBoundariesConverter <T>((val) => ConstrainBoundaries(val).value)
            {
                Culture = CultureInfo.InvariantCulture
            };

            #region parameters default depending on T
            //sbyte
            if (typeof(T) == typeof(sbyte) || typeof(T) == typeof(sbyte?))
            {
                _minDefault  = (T)(object)sbyte.MinValue;
                _maxDefault  = (T)(object)sbyte.MaxValue;
                _stepDefault = (T)(object)(sbyte)1;
            }
            // byte
            else if (typeof(T) == typeof(byte) || typeof(T) == typeof(byte?))
            {
                _minDefault  = (T)(object)byte.MinValue;
                _maxDefault  = (T)(object)byte.MaxValue;
                _stepDefault = (T)(object)(byte)1;
            }
            // short
            else if (typeof(T) == typeof(short) || typeof(T) == typeof(short?))
            {
                _minDefault  = (T)(object)short.MinValue;
                _maxDefault  = (T)(object)short.MaxValue;
                _stepDefault = (T)(object)(short)1;
            }
            // ushort
            else if (typeof(T) == typeof(ushort) || typeof(T) == typeof(ushort?))
            {
                _minDefault  = (T)(object)ushort.MinValue;
                _maxDefault  = (T)(object)ushort.MaxValue;
                _stepDefault = (T)(object)(ushort)1;
            }
            // int
            else if (typeof(T) == typeof(int) || typeof(T) == typeof(int?))
            {
                _minDefault  = (T)(object)int.MinValue;
                _maxDefault  = (T)(object)int.MaxValue;
                _stepDefault = (T)(object)1;
            }
            // uint
            else if (typeof(T) == typeof(uint) || typeof(T) == typeof(uint?))
            {
                _minDefault  = (T)(object)uint.MinValue;
                _maxDefault  = (T)(object)uint.MaxValue;
                _stepDefault = (T)(object)1u;
            }
            // long
            else if (typeof(T) == typeof(long) || typeof(T) == typeof(long?))
            {
                _minDefault  = (T)(object)long.MinValue;
                _maxDefault  = (T)(object)long.MaxValue;
                _stepDefault = (T)(object)1L;
            }
            // ulong
            else if (typeof(T) == typeof(ulong) || typeof(T) == typeof(ulong?))
            {
                _minDefault  = (T)(object)ulong.MinValue;
                _maxDefault  = (T)(object)ulong.MaxValue;
                _stepDefault = (T)(object)1ul;
            }
            // float
            else if (typeof(T) == typeof(float) || typeof(T) == typeof(float?))
            {
                _minDefault  = (T)(object)float.MinValue;
                _maxDefault  = (T)(object)float.MaxValue;
                _stepDefault = (T)(object)1.0f;
            }
            // double
            else if (typeof(T) == typeof(double) || typeof(T) == typeof(double?))
            {
                _minDefault  = (T)(object)double.MinValue;
                _maxDefault  = (T)(object)double.MaxValue;
                _stepDefault = (T)(object)1.0;
            }
            // decimal
            else if (typeof(T) == typeof(decimal) || typeof(T) == typeof(decimal?))
            {
                _minDefault  = (T)(object)decimal.MinValue;
                _maxDefault  = (T)(object)decimal.MaxValue;
                _stepDefault = (T)(object)1M;
            }
            #endregion
        }
示例#2
0
        public MudNumericField() : base()
        {
            _validateInstance = new Func <T, Task <bool> >(ValidateInput);
            _inputConverter   = new NumericBoundariesConverter <T>((val) => ConstrainBoundaries(val).value)
            {
                FilterFunc = CleanText,
                Culture    = CultureInfo.InvariantCulture
            };

            #region parameters default depending on T

            //sbyte
            if (typeof(T) == typeof(sbyte) || typeof(T) == typeof(sbyte?))
            {
                _minDefault  = (T)(object)sbyte.MinValue;
                _maxDefault  = (T)(object)sbyte.MaxValue;
                _stepDefault = (T)(object)(sbyte)1;
            }
            // byte
            else if (typeof(T) == typeof(byte) || typeof(T) == typeof(byte?))
            {
                _minDefault  = (T)(object)byte.MinValue;
                _maxDefault  = (T)(object)byte.MaxValue;
                _stepDefault = (T)(object)(byte)1;
            }
            // short
            else if (typeof(T) == typeof(short) || typeof(T) == typeof(short?))
            {
                _minDefault  = (T)(object)short.MinValue;
                _maxDefault  = (T)(object)short.MaxValue;
                _stepDefault = (T)(object)(short)1;
            }
            // ushort
            else if (typeof(T) == typeof(ushort) || typeof(T) == typeof(ushort?))
            {
                _minDefault  = (T)(object)ushort.MinValue;
                _maxDefault  = (T)(object)ushort.MaxValue;
                _stepDefault = (T)(object)(ushort)1;
            }
            // int
            else if (typeof(T) == typeof(int) || typeof(T) == typeof(int?))
            {
                _minDefault  = (T)(object)int.MinValue;
                _maxDefault  = (T)(object)int.MaxValue;
                _stepDefault = (T)(object)1;
            }
            // uint
            else if (typeof(T) == typeof(uint) || typeof(T) == typeof(uint?))
            {
                _minDefault  = (T)(object)uint.MinValue;
                _maxDefault  = (T)(object)uint.MaxValue;
                _stepDefault = (T)(object)1u;
            }
            // long
            else if (typeof(T) == typeof(long) || typeof(T) == typeof(long?))
            {
                _minDefault  = (T)(object)long.MinValue;
                _maxDefault  = (T)(object)long.MaxValue;
                _stepDefault = (T)(object)1L;
            }
            // ulong
            else if (typeof(T) == typeof(ulong) || typeof(T) == typeof(ulong?))
            {
                _minDefault  = (T)(object)ulong.MinValue;
                _maxDefault  = (T)(object)ulong.MaxValue;
                _stepDefault = (T)(object)1ul;
            }
            // float
            else if (typeof(T) == typeof(float) || typeof(T) == typeof(float?))
            {
                _minDefault  = (T)(object)float.MinValue;
                _maxDefault  = (T)(object)float.MaxValue;
                _stepDefault = (T)(object)1.0f;
            }
            // double
            else if (typeof(T) == typeof(double) || typeof(T) == typeof(double?))
            {
                _minDefault  = (T)(object)double.MinValue;
                _maxDefault  = (T)(object)double.MaxValue;
                _stepDefault = (T)(object)1.0;
            }
            // decimal
            else if (typeof(T) == typeof(decimal) || typeof(T) == typeof(decimal?))
            {
                _minDefault  = (T)(object)decimal.MinValue;
                _maxDefault  = (T)(object)decimal.MaxValue;
                _stepDefault = (T)(object)1M;
            }

            #endregion parameters default depending on T
        }