Beispiel #1
0
        private PrimitiveDataType CompensatePrimitiveDefaultFacets(PrimitiveDataType inputDataType)
        {
            var inputBinary = inputDataType as BinaryDataType;
            var inputString = inputDataType as StringDataType;

            if (inputBinary == null && inputString == null)
            {
                return(inputDataType);
            }

            int?maxLength = null;

            if (inputDataType.HasFacet <MaxLengthFacet>())
            {
                maxLength = inputDataType.GetFacet <MaxLengthFacet>().Value;
            }

            bool isUnicode = inputDataType.GetFacetValue <IsUnicodeFacet, bool>(true);

            if (inputBinary != null)
            {
                return(EdmDataTypes.Binary(maxLength)
                       .Nullable(inputDataType.IsNullable));
            }
            else
            {
                return(EdmDataTypes.String(maxLength, isUnicode)
                       .Nullable(inputDataType.IsNullable));
            }
        }
Beispiel #2
0
            /// <summary>
            /// Gets the short qualified Edm name
            /// </summary>
            /// <param name="dataType">The data type.</param>
            /// <returns>short qualified Edm name</returns>
            public string Visit(PrimitiveDataType dataType)
            {
                EnumDataType enumDataType = dataType as EnumDataType;

                if (enumDataType != null)
                {
                    return(enumDataType.Definition.Name);
                }

                bool isValid = dataType.HasFacet <EdmNamespaceFacet>() &&
                               dataType.HasFacet <EdmTypeNameFacet>();

                ExceptionUtilities.Assert(isValid, "{0} is not a valid Edm primitive data type. No required facets.", dataType);

                string name = dataType.GetFacet <EdmTypeNameFacet>().Value;

                return(name);
            }
Beispiel #3
0
        private static PrimitiveDataType ResolveCommonPrecisionAndScale(PrimitiveDataType leftType, PrimitiveDataType rightType, PrimitiveDataType commonType)
        {
            if (commonType.HasFacet <NumericPrecisionFacet>())
            {
                ExceptionUtilities.Assert(commonType is FixedPointDataType, "Precision and scale facets are not expected on type {}.", commonType.ToString());
                var commonPrecision = GetCommonPrecision(leftType, rightType);
                var commonScale     = GetCommonScale(leftType, rightType);
                commonType = EdmDataTypes.Decimal(commonPrecision, commonScale);
            }

            return(commonType);
        }
        private IEdmPrimitiveTypeReference GetTemporalTypeReference(PrimitiveDataType dataType)
        {
            IEdmPrimitiveType typeDefinition = this.GetEdmTypeDefinition(dataType);

            int?precision = null;

            if (dataType.HasFacet <TimePrecisionFacet>())
            {
                precision = dataType.GetFacet <TimePrecisionFacet>().Value;
            }

            var typeReference = new EdmTemporalTypeReference(
                typeDefinition,
                dataType.IsNullable,
                precision);

            return(typeReference);
        }
Beispiel #5
0
        private static PrimitiveDataType ResolveCommonPrecisionAndScale(PrimitiveDataType leftType, PrimitiveDataType rightType, PrimitiveDataType commonType)
        {
            if (commonType.HasFacet<NumericPrecisionFacet>())
            {
                ExceptionUtilities.Assert(commonType is FixedPointDataType, "Precision and scale facets are not expected on type {}.", commonType.ToString());
                var commonPrecision = GetCommonPrecision(leftType, rightType);
                var commonScale = GetCommonScale(leftType, rightType);
                commonType = EdmDataTypes.Decimal(commonPrecision, commonScale);
            }

            return commonType;
        }
        private PrimitiveDataType CompensatePrimitiveDefaultFacets(PrimitiveDataType inputDataType)
        {
            var inputBinary = inputDataType as BinaryDataType;
            var inputString = inputDataType as StringDataType;

            if (inputBinary == null && inputString == null)
            {
                return inputDataType;
            }

            int? maxLength = null;
            if (inputDataType.HasFacet<MaxLengthFacet>())
            {
                maxLength = inputDataType.GetFacet<MaxLengthFacet>().Value;
            }

            bool isUnicode = inputDataType.GetFacetValue<IsUnicodeFacet, bool>(true);

            if (inputBinary != null)
            {
                return EdmDataTypes.Binary(maxLength)
                                   .Nullable(inputDataType.IsNullable);
            }
            else
            {
                return EdmDataTypes.String(maxLength, isUnicode)
                                   .Nullable(inputDataType.IsNullable);
            }
        }