Esempio n. 1
0
        private void Validate(string declaringTypeName)
        {
            if (_defaultValue == _notInitializedSentinel)
            {
                if (_isConstant)
                {
                    throw EntityUtil.MissingDefaultValueForConstantFacet(_facetName, declaringTypeName);
                }
            }
            else if (FacetDescription.IsNumericType(_facetType))
            {
                if (_isConstant)
                {
                    // Either both of them are not specified or both of them have the same value
                    if ((_minValue.HasValue != _maxValue.HasValue) ||
                        (_minValue.HasValue && _minValue.Value != _maxValue.Value))
                    {
                        throw EntityUtil.MinAndMaxValueMustBeSameForConstantFacet(_facetName, declaringTypeName);
                    }
                }

                // If its not constant, then both of the minValue and maxValue must be specified
                else if (!_minValue.HasValue || !_maxValue.HasValue)
                {
                    throw EntityUtil.BothMinAndMaxValueMustBeSpecifiedForNonConstantFacet(_facetName, declaringTypeName);
                }
                else if (_minValue.Value == _maxValue)
                {
                    throw EntityUtil.MinAndMaxValueMustBeDifferentForNonConstantFacet(_facetName, declaringTypeName);
                }
                else if (_minValue < 0 || _maxValue < 0)
                {
                    throw EntityUtil.MinAndMaxMustBePositive(_facetName, declaringTypeName);
                }
                else if (_minValue > _maxValue)
                {
                    throw EntityUtil.MinMustBeLessThanMax(_minValue.ToString(), _facetName, declaringTypeName);
                }
            }
        }