예제 #1
0
        /// <summary>
        /// The constructor for constructing a facet description object
        /// </summary>
        /// <param name="facetName">The name of this facet</param>
        /// <param name="facetType">The type of this facet</param>
        /// <param name="minValue">The min value for this facet</param>
        /// <param name="maxValue">The max value for this facet</param>
        /// <param name="defaultValue">The default value for this facet</param>
        /// <exception cref="System.ArgumentNullException">Thrown if either facetName, facetType or applicableType arguments are null</exception>
        internal FacetDescription(string facetName,
                                  EdmType facetType,
                                  int?minValue,
                                  int?maxValue,
                                  object defaultValue)
        {
            EntityUtil.CheckStringArgument(facetName, "facetName");
            EntityUtil.GenericCheckArgumentNull(facetType, "facetType");

            if (minValue.HasValue || maxValue.HasValue)
            {
                Debug.Assert(FacetDescription.IsNumericType(facetType), "Min and Max Values can only be specified for numeric facets");

                if (minValue.HasValue && maxValue.HasValue)
                {
                    Debug.Assert(minValue != maxValue, "minValue should not be equal to maxValue");
                }
            }

            _facetName    = facetName;
            _facetType    = facetType;
            _minValue     = minValue;
            _maxValue     = maxValue;
            _defaultValue = defaultValue;
        }
예제 #2
0
 private static void UpdateMinMaxValueForConstant(string facetName, EdmType facetType, ref int?minValue, ref int?maxValue, object defaultValue)
 {
     if (FacetDescription.IsNumericType(facetType))
     {
         if (facetName == EdmProviderManifest.PrecisionFacetName ||
             facetName == EdmProviderManifest.ScaleFacetName)
         {
             minValue = (int?)((byte?)defaultValue);
             maxValue = (int?)((byte?)defaultValue);
         }
         else
         {
             minValue = (int?)defaultValue;
             maxValue = (int?)defaultValue;
         }
     }
 }
예제 #3
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);
                }
            }
        }