Example #1
0
        public static Envelope Create(IValid valid, string strWidth, string strLength)
        {
            float width = valid.GetValidFloatArg(strWidth);

            float length = valid.GetValidFloatArg(strLength);

            if (width <= 0.0 || length <= 0.0)
            {
                throw new ArgumentOutOfRangeException(Settings.NEGATIVE_DATA);
            }

            return(new Envelope(width, length));
        }
        public static Board GetValidBoard(this IValid valid, string rowIndex, string columnIndex)
        {
            byte numberOfRows    = valid.GetValidByteArg(rowIndex);
            byte NumverOfColumns = valid.GetValidByteArg(columnIndex);

            if (numberOfRows <= 0 || NumverOfColumns <= 0)
            {
                throw new ArgumentOutOfRangeException(Settings.INSTRUCTION);
            }
            if (numberOfRows > 30 || NumverOfColumns > 100)
            {
                throw new ArgumentOutOfRangeException(Settings.BIG_NUM);
            }

            return(new Board(numberOfRows, NumverOfColumns));
        }
        public static byte TryPowerParse(this IValid valid, string str)
        {
            byte power = valid.
                         GetValidByteArg(str);

            if (power % 2 == 1)
            {
                throw new Exception(Settings.LENGTH_ERROR);
            }
            if (power > 6)
            {
                throw new Exception(Settings.VALUE_ERROR);
            }

            return(power);
        }
Example #4
0
    private void SetPropertyValues(IValid obj)
    {
        var properties = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

        foreach (var property in properties)
        {
            if (property.CanRead)
            {
                var validObject = property.GetValue(obj) as IValid;

                if (validObject != null)
                {
                    validObject.Valid = obj.Valid;

                    SetPropertyValues(validObject);
                }
            }
        }
    }
 public Application(IValid valid, IView view)
 {
     Validation = valid;
     View       = view;
 }
Example #6
0
 private void CheckValid(IValid <double> unit, double value)
 {
     unit.IsValid(value);
 }
 public Application(IValid valid, IView view, ISourceAlgorithm typeAlgorithm)
 {
     Validation    = valid;
     View          = view;
     TypeAlgorithm = typeAlgorithm;
 }
Example #8
0
 /// <summary>
 /// 添加属性合法性校验。
 /// </summary>
 /// <param name="propertyInfo">属性信息。</param>
 /// <param name="validOption">合法性校验选项。</param>
 /// <param name="valid">合法性校验接口实例。</param>
 protected void AddPropertyValid(PropertyInfo propertyInfo, ValidOption validOption, IValid valid)
 {
     PropertyValidSet.Add(propertyInfo, new Tuple <ValidOption, IValid>(validOption, valid));
 }