Ejemplo n.º 1
0
        void CheckValueBoundaries(CfgAttribute itemAttributes, string name, object value)
        {
            if (!itemAttributes.MinValueSet && !itemAttributes.MaxValueSet)
            {
                return;
            }

            var comparable = value as IComparable;

            if (comparable == null)
            {
                Events.ValueIsNotComparable(name, value);
            }
            else
            {
                if (itemAttributes.MinValueSet)
                {
                    if (comparable.CompareTo(itemAttributes.minValue) < 0)
                    {
                        Events.ValueTooSmall(name, value, itemAttributes.minValue);
                    }
                }

                if (!itemAttributes.MaxValueSet)
                {
                    return;
                }

                if (comparable.CompareTo(itemAttributes.maxValue) > 0)
                {
                    Events.ValueTooBig(name, value, itemAttributes.maxValue);
                }
            }
        }
Ejemplo n.º 2
0
        public CfgMetadata(PropertyInfo propertyInfo, CfgAttribute attribute)
        {
            PropertyInfo = propertyInfo;
            Attribute    = attribute;

            if (!string.IsNullOrEmpty(attribute.domain))
            {
                var comparer = attribute.ignoreCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal;
                _domainSet = new HashSet <string>(attribute.domain.Split(new[] { attribute.delimiter }, StringSplitOptions.None).Distinct(), comparer);
            }
        }
Ejemplo n.º 3
0
        void CheckValueLength(CfgAttribute itemAttributes, string name, string value)
        {
            if (itemAttributes.MinLengthSet)
            {
                if (value.Length < itemAttributes.minLength)
                {
                    Events.ValueTooShort(name, value, itemAttributes.minLength);
                }
            }

            if (!itemAttributes.MaxLengthSet)
            {
                return;
            }

            if (value.Length > itemAttributes.maxLength)
            {
                Events.ValueTooLong(name, value, itemAttributes.maxLength);
            }
        }
Ejemplo n.º 4
0
        public CfgMetadata(PropertyInfo propertyInfo, CfgAttribute attribute) {
            PropertyInfo = propertyInfo;
            Attribute = attribute;

            if (!string.IsNullOrEmpty(attribute.domain)) {
                if (attribute.domainDelimiter == default(char)) {
                    attribute.domainDelimiter = DefaultDelimiter;
                }
                var comparer = attribute.ignoreCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal;
                _domainSet = new HashSet<string>(attribute.domain.Split(new[] { attribute.domainDelimiter }, StringSplitOptions.None).Distinct(), comparer);
            }

            if (string.IsNullOrEmpty(attribute.validators)) return;

            if (attribute.validatorDelimiter == default(char)) {
                attribute.validatorDelimiter = DefaultDelimiter;
            }

            _validatorSet =
                new HashSet<string>(
                    attribute.validators.Split(new[] { attribute.validatorDelimiter }, StringSplitOptions.None).Distinct(),
                    attribute.ignoreCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal);
        }
Ejemplo n.º 5
0
        void CheckValueBoundaries(CfgAttribute itemAttributes, string name, object value) {
            if (!itemAttributes.MinValueSet && !itemAttributes.MaxValueSet)
                return;

            var comparable = value as IComparable;
            if (comparable == null) {
                Events.ValueIsNotComparable(name, value);
            } else {
                if (itemAttributes.MinValueSet) {
                    if (comparable.CompareTo(itemAttributes.minValue) < 0) {
                        Events.ValueTooSmall(name, value, itemAttributes.minValue);
                    }
                }

                if (!itemAttributes.MaxValueSet)
                    return;

                if (comparable.CompareTo(itemAttributes.maxValue) > 0) {
                    Events.ValueTooBig(name, value, itemAttributes.maxValue);
                }
            }
        }
Ejemplo n.º 6
0
        void CheckValueLength(CfgAttribute itemAttributes, string name, string value) {
            if (itemAttributes.MinLengthSet) {
                if (value.Length < itemAttributes.minLength) {
                    Events.ValueTooShort(name, value, itemAttributes.minLength);
                }
            }

            if (!itemAttributes.MaxLengthSet)
                return;

            if (value.Length > itemAttributes.maxLength) {
                Events.ValueTooLong(name, value, itemAttributes.maxLength);
            }
        }