Ejemplo n.º 1
0
        public void Decorate(object attribute, DisplayMetadata modelMetaData)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            if (!(attribute is StringLengthAttribute))
            {
                throw new ArgumentException("Attribute type is not StringLengthAttribute", nameof(attribute));
            }

            var stringLengthttribtue = (StringLengthAttribute)attribute;

            modelMetaData.AddAdditionalValueWithValidationMessage("Maxlength", stringLengthttribtue.MaximumLength, stringLengthttribtue);

            if (stringLengthttribtue.MinimumLength > 0)
            {
                modelMetaData.AddAdditionalValueWithValidationMessage("Minlength", stringLengthttribtue.MinimumLength, stringLengthttribtue);
            }
        }
Ejemplo n.º 2
0
        public void Decorate(object attribute, DisplayMetadata modelMetaData)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            if (!(attribute is RangeAttribute))
            {
                throw new ArgumentException("Attribute type is not RangeAttribute", nameof(attribute));
            }

            var rangeLengthttribtue = (RangeAttribute)attribute;

            string minAttribute = null;
            string maxAttribute = null;

            if (rangeLengthttribtue.OperandType == typeof(string))
            {
                minAttribute = "Minlength";
                maxAttribute = "Maxlength";
            }
            else
            {
                minAttribute = "Min";
                maxAttribute = "Max";
            }

            if (minAttribute != null)
            {
                if (rangeLengthttribtue.Minimum != null)
                {
                    modelMetaData.AddAdditionalValueWithValidationMessage(minAttribute, rangeLengthttribtue.Minimum, rangeLengthttribtue);
                }
                if (rangeLengthttribtue.Maximum != null)
                {
                    modelMetaData.AddAdditionalValueWithValidationMessage(maxAttribute, rangeLengthttribtue.Maximum, rangeLengthttribtue);
                }
            }
        }
Ejemplo n.º 3
0
        public void Decorate(object attribute, DisplayMetadata modelMetaData)
        {
            if (attribute == null) throw new ArgumentNullException(nameof(attribute));

            if (!(attribute is MaxLengthAttribute))
            {
                throw new ArgumentException("Attribute type is not MaxLengthAttribute", nameof(attribute));
            }

            var maxLengthttribtue = (MaxLengthAttribute)attribute;

            modelMetaData.AddAdditionalValueWithValidationMessage("Maxlength", maxLengthttribtue.Length, maxLengthttribtue);
        }
Ejemplo n.º 4
0
        public void Decorate(object attribute, DisplayMetadata modelMetaData)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            if (!(attribute is CompareAttribute))
            {
                throw new ArgumentException("Attribute type is not CompareAttribute", nameof(attribute));
            }


            var compareAttribtue = (CompareAttribute)attribute;
            var otherProperty    = compareAttribtue.OtherProperty;
            var valAttribute     = compareAttribtue;

            modelMetaData.AddAdditionalValueWithValidationMessage("Match", otherProperty, valAttribute);
        }