当前位置: 首页>>代码示例>>C#>>正文


C# IEdmTypeReference.IsPrimitive方法代码示例

本文整理汇总了C#中IEdmTypeReference.IsPrimitive方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.IsPrimitive方法的具体用法?C# IEdmTypeReference.IsPrimitive怎么用?C# IEdmTypeReference.IsPrimitive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEdmTypeReference的用法示例。


在下文中一共展示了IEdmTypeReference.IsPrimitive方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetEdmTypeSerializer

        /// <summary>
        /// Gets the serializer for the given EDM type reference.
        /// </summary>
        /// <param name="edmType">The EDM type reference involved in the serializer.</param>
        /// <returns>The serializer instance.</returns>
        public override ODataEdmTypeSerializer GetEdmTypeSerializer(IEdmTypeReference edmType)
        {
            if (edmType.IsPrimitive())
            {
                return this.primitiveSerializer;
            }

            return base.GetEdmTypeSerializer(edmType);
        }
开发者ID:chinadragon0515,项目名称:ODataSamples,代码行数:14,代码来源:CustomizedSerializerProvider.cs

示例2: Convert

 private object Convert(object value, IEdmTypeReference parameterType, ODataDeserializerContext readContext)
 {
     if (parameterType.IsPrimitive())
     {
         return value;
     }
     else
     {
         ODataEntryDeserializer deserializer = _provider.GetODataDeserializer(parameterType);
         return deserializer.ReadInline(value, readContext);
     }
 }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:12,代码来源:ODataActionPayloadDeserializer.cs

示例3: CreateODataValue

        /// <inheritdoc/>
        public sealed override ODataValue CreateODataValue(object graph, IEdmTypeReference expectedType, ODataSerializerContext writeContext)
        {
            if (!expectedType.IsPrimitive())
            {
                throw Error.InvalidOperation(SRResources.CannotWriteType, typeof(ODataPrimitiveSerializer), expectedType.FullName());
            }

            ODataPrimitiveValue value = CreateODataPrimitiveValue(graph, expectedType.AsPrimitive(), writeContext);
            if (value == null)
            {
                return new ODataNullValue();
            }

            return value;
        }
开发者ID:richarddwelsh,项目名称:aspnetwebstack,代码行数:16,代码来源:ODataPrimitiveSerializer.cs

示例4: GetValueTypeNameForWriting

        /// <summary>
        /// Determines the type name to write to the payload.  Json Light type names are only written into the payload for open properties
        /// or if the payload type name is more derived than the model type name.
        /// </summary>
        /// <param name="value">The ODataValue whose type name is to be written.</param>
        /// <param name="typeReferenceFromMetadata">The type as expected by the model.</param>
        /// <param name="typeReferenceFromValue">The type resolved from the value.</param>
        /// <param name="isOpenProperty">true if the type name belongs to an open property, false otherwise.</param>
        /// <returns>Type name to write to the payload, or null if no type should be written.</returns>
        internal override string GetValueTypeNameForWriting(
            ODataValue value,
            IEdmTypeReference typeReferenceFromMetadata,
            IEdmTypeReference typeReferenceFromValue,
            bool isOpenProperty)
        {
            SerializationTypeNameAnnotation typeNameAnnotation = value.GetAnnotation<SerializationTypeNameAnnotation>();
            if (typeNameAnnotation != null)
            {
                return typeNameAnnotation.TypeName;
            }

            // Do not write type name when the type is native json type.
            if (typeReferenceFromValue != null
                && typeReferenceFromValue.IsPrimitive()
                && JsonSharedUtils.ValueTypeMatchesJsonType((ODataPrimitiveValue)value, typeReferenceFromValue.AsPrimitive()))
            {
                return null;
            }

            return GetTypeNameFromValue(value);
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:31,代码来源:JsonFullMetadataTypeNameOracle.cs

示例5: GetValueTypeNameForWriting

        /// <summary>
        /// Determines the type name to write to the payload.  Json Light type names are only written into the payload for open properties
        /// or if the payload type name is more derived than the model type name.
        /// </summary>
        /// <param name="value">The ODataValue whose type name is to be written.</param>
        /// <param name="typeReferenceFromMetadata">The type as expected by the model.</param>
        /// <param name="typeReferenceFromValue">The type resolved from the value.</param>
        /// <param name="isOpenProperty">true if the type name belongs to an open property, false otherwise.</param>
        /// <returns>Type name to write to the payload, or null if no type should be written.</returns>
        internal override string GetValueTypeNameForWriting(
            ODataValue value,
            IEdmTypeReference typeReferenceFromMetadata,
            IEdmTypeReference typeReferenceFromValue,
            bool isOpenProperty)
        {
            SerializationTypeNameAnnotation typeNameAnnotation = value.GetAnnotation<SerializationTypeNameAnnotation>();
            if (typeNameAnnotation != null)
            {
                return typeNameAnnotation.TypeName;
            }

            if (typeReferenceFromValue != null)
            {
                // Write type name when the type in the payload is more derived than the type from metadata.
                if (typeReferenceFromMetadata != null && typeReferenceFromMetadata.Definition.AsActualType().ODataFullName() != typeReferenceFromValue.ODataFullName())
                {
                    return typeReferenceFromValue.ODataFullName();
                }

                // Note: When writing derived complexType value in a payload, we don't have the expected type. 
                // So always write @odata.type for top-level derived complextype.
                if (typeReferenceFromMetadata == null && typeReferenceFromValue.IsComplex())
                {
                    if ((typeReferenceFromValue as IEdmComplexTypeReference).ComplexDefinition().BaseType != null)
                    {
                        return typeReferenceFromValue.ODataFullName();
                    }
                }

                // Do not write type name when the type is native json type.
                if (typeReferenceFromValue.IsPrimitive() && JsonSharedUtils.ValueTypeMatchesJsonType((ODataPrimitiveValue)value, typeReferenceFromValue.AsPrimitive()))
                {
                    return null;
                }
            }

            if (!isOpenProperty)
            {
                // Do not write type name for non-open properties since we expect the reader to have an expected type (via API or context URI) and thus not need it.
                return null;
            }

            return GetTypeNameFromValue(value);
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:54,代码来源:JsonMinimalMetadataTypeNameOracle.cs

示例6: TryCastPrimitiveAsType

        internal static bool TryCastPrimitiveAsType(this IEdmPrimitiveValue expression, IEdmTypeReference type, out IEnumerable<EdmError> discoveredErrors)
        {
            if (!type.IsPrimitive())
            {
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.PrimitiveConstantExpressionNotValidForNonPrimitiveType, Edm.Strings.EdmModel_Validator_Semantic_PrimitiveConstantExpressionNotValidForNonPrimitiveType) };
                return false;
            }

            switch (expression.ValueKind)
            {
                case EdmValueKind.Binary:
                    return TryCastBinaryConstantAsType((IEdmBinaryConstantExpression)expression, type, out discoveredErrors);
                case EdmValueKind.Boolean:
                    return TryCastBooleanConstantAsType((IEdmBooleanConstantExpression)expression, type, out discoveredErrors);
                case EdmValueKind.DateTimeOffset:
                    return TryCastDateTimeOffsetConstantAsType((IEdmDateTimeOffsetConstantExpression)expression, type, out discoveredErrors);
                case EdmValueKind.Decimal:
                    return TryCastDecimalConstantAsType((IEdmDecimalConstantExpression)expression, type, out discoveredErrors);
                case EdmValueKind.Floating:
                    return TryCastFloatingConstantAsType((IEdmFloatingConstantExpression)expression, type, out discoveredErrors);
                case EdmValueKind.Guid:
                    return TryCastGuidConstantAsType((IEdmGuidConstantExpression)expression, type, out discoveredErrors);
                case EdmValueKind.Integer:
                    return TryCastIntegerConstantAsType((IEdmIntegerConstantExpression)expression, type, out discoveredErrors);
                case EdmValueKind.String:
                    return TryCastStringConstantAsType((IEdmStringConstantExpression)expression, type, out discoveredErrors);
                case EdmValueKind.Duration:
                    return TryCastDurationConstantAsType((IEdmDurationConstantExpression)expression, type, out discoveredErrors);
                case EdmValueKind.Date:
                    return TryCastDateConstantAsType((IEdmDateConstantExpression)expression, type, out discoveredErrors);
                case EdmValueKind.TimeOfDay:
                    return TryCastTimeOfDayConstantAsType((IEdmTimeOfDayConstantExpression)expression, type, out discoveredErrors);
                default:
                    discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType) };
                    return false;
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:37,代码来源:ExpressionTypeChecker.cs

示例7: GetDefaultValue

        internal static object GetDefaultValue(IEdmTypeReference propertyType)
        {
            Contract.Assert(propertyType != null);

            bool isCollection = propertyType.IsCollection();
            if (!propertyType.IsNullable || isCollection)
            {
                Type clrType = GetClrTypeForUntypedDelta(propertyType);

                if (propertyType.IsPrimitive() ||
                    (isCollection && propertyType.AsCollection().ElementType().IsPrimitive()))
                {
                    // primitive or primitive collection
                    return Activator.CreateInstance(clrType);
                }
                else
                {
                    // IEdmObject
                    return Activator.CreateInstance(clrType, propertyType);
                }
            }

            return null;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:24,代码来源:EdmStructuredObject.cs

示例8: ReadCollectionValue

        /// <summary>
        /// Deserializes the given <paramref name="collectionValue"/> under the given <paramref name="readContext"/>.
        /// </summary>
        /// <param name="collectionValue">The <see cref="ODataCollectionValue"/> to deserialize.</param>
        /// <param name="elementType">The element type of the collection to read.</param>
        /// <param name="readContext">The deserializer context.</param>
        /// <returns>The deserialized collection.</returns>
        public virtual IEnumerable ReadCollectionValue(ODataCollectionValue collectionValue, IEdmTypeReference elementType,
            ODataDeserializerContext readContext)
        {
            if (collectionValue == null)
            {
                throw Error.ArgumentNull("collectionValue");
            }
            if (elementType == null)
            {
                throw Error.ArgumentNull("elementType");
            }

            ODataEdmTypeDeserializer deserializer = DeserializerProvider.GetEdmTypeDeserializer(elementType);
            if (deserializer == null)
            {
                throw new SerializationException(
                    Error.Format(SRResources.TypeCannotBeDeserialized, elementType.FullName(), typeof(ODataMediaTypeFormatter).Name));
            }

            foreach (object entry in collectionValue.Items)
            {
                if (elementType.IsPrimitive())
                {
                    yield return entry;
                }
                else
                {
                    yield return deserializer.ReadInline(entry, elementType, readContext);
                }
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:38,代码来源:ODataCollectionDeserializer.cs

示例9: GetEdmTypeSerializer

        /// <summary>
        /// Gets the serializer for the given EDM type reference.
        /// </summary>
        /// <param name="edmType">The EDM type reference involved in the serializer.</param>
        /// <returns>The serializer instance.</returns>
        public override ODataEdmTypeSerializer GetEdmTypeSerializer(IEdmTypeReference edmType)
        {
            if (edmType.IsEntity())
            {
                return this.entityTypeSerializer;
            }

            if (edmType.IsComplex())
            {
                return this.complexTypeSerializer;
            }

            if (edmType.IsPrimitive())
            {
                return this.primitiveSerializer;
            }

            if (edmType.IsEnum())
            {
                return this.enumSerializer;
            }

            if (edmType.IsCollection())
            {
                if (edmType.AsCollection().ElementType().IsEntity())
                {
                    return this.feedSerializer;
                }

                return this.collectionSerializer;
            }

            return base.GetEdmTypeSerializer(edmType);
        }
开发者ID:kosinsky,项目名称:RESTier,代码行数:39,代码来源:DefaultRestierSerializerProvider.cs

示例10: GetClrTypeName

        //fill all properties/name of the class template

        private string GetClrTypeName(IEdmTypeReference edmTypeReference)
        {
            string clrTypeName = edmTypeReference.ToString();
            IEdmType edmType = edmTypeReference.Definition;


            if (edmTypeReference.IsPrimitive()) return EdmToClr(edmType as IEdmPrimitiveType);

            //@@@ v1.0.0-rc2
            if (edmTypeReference.IsEnum())
            {
                var ent = edmType as IEdmEnumType;
                if (ent != null) return ent.Name;
            }

            if (edmTypeReference.IsComplex())
            {
                var edmComplexType = edmType as IEdmComplexType;
                if (edmComplexType != null) return edmComplexType.Name;
            }

            if (edmTypeReference.IsEntity())
            {
                var ent = edmType as IEdmEntityType;
                if (ent != null) return ent.Name;
            }

            if (edmTypeReference.IsCollection())
            {

                IEdmCollectionType edmCollectionType = edmType as IEdmCollectionType;
                if (edmCollectionType != null)
                {
                    IEdmTypeReference elementTypeReference = edmCollectionType.ElementType;
                    IEdmPrimitiveType primitiveElementType = elementTypeReference.Definition as IEdmPrimitiveType;
                    if (primitiveElementType == null)
                    {
                        IEdmSchemaElement schemaElement = elementTypeReference.Definition as IEdmSchemaElement;
                        if (schemaElement != null)
                        {
                            clrTypeName = schemaElement.Name;
                            //@@@ 1.0.0-rc2
                            // clrTypeName = string.Format("ICollection<{0}>", clrTypeName);
                            clrTypeName = string.Format("List<{0}>", clrTypeName); //to support RestSharp
                        }
                        return clrTypeName;
                    }

                    clrTypeName = EdmToClr(primitiveElementType);
                    clrTypeName = string.Format("List<{0}>", clrTypeName);
                }
                return clrTypeName;
            }//IsCollection
            return clrTypeName;
        }
开发者ID:moh-hassan,项目名称:odata2poco,代码行数:57,代码来源:Poco.cs

示例11: TestTypeMatch

		private static bool TestTypeMatch(this IEdmTypeReference expressionType, IEdmTypeReference assertedType, EdmLocation location, out IEnumerable<EdmError> discoveredErrors)
		{
			if (expressionType.TestNullabilityMatch(assertedType, location, out discoveredErrors))
			{
				if (expressionType.TypeKind() == EdmTypeKind.None || expressionType.IsBad())
				{
					discoveredErrors = Enumerable.Empty<EdmError>();
					return true;
				}
				else
				{
					if (!expressionType.IsPrimitive() || !assertedType.IsPrimitive())
					{
						if (!expressionType.Definition.IsEquivalentTo(assertedType.Definition))
						{
							EdmError[] edmError = new EdmError[1];
							edmError[0] = new EdmError(location, EdmErrorCode.ExpressionNotValidForTheAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionNotValidForTheAssertedType);
							discoveredErrors = edmError;
							return false;
						}
					}
					else
					{
						if (!expressionType.PrimitiveKind().PromotesTo(assertedType.AsPrimitive().PrimitiveKind()))
						{
							EdmError[] edmErrorArray = new EdmError[1];
							edmErrorArray[0] = new EdmError(location, EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindCannotPromoteToAssertedType(expressionType.FullName(), assertedType.FullName()));
							discoveredErrors = edmErrorArray;
							return false;
						}
					}
					discoveredErrors = Enumerable.Empty<EdmError>();
					return true;
				}
			}
			else
			{
				return false;
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:40,代码来源:ExpressionTypeChecker.cs

示例12: TryAssertPrimitiveAsType

		internal static bool TryAssertPrimitiveAsType(this IEdmPrimitiveValue expression, IEdmTypeReference type, out IEnumerable<EdmError> discoveredErrors)
		{
			EdmError[] edmError;
			if (type.IsPrimitive())
			{
				EdmValueKind valueKind = expression.ValueKind;
				switch (valueKind)
				{
					case EdmValueKind.Binary:
					{
						return ExpressionTypeChecker.TryAssertBinaryConstantAsType((IEdmBinaryConstantExpression)expression, type, out discoveredErrors);
					}
					case EdmValueKind.Boolean:
					{
						return ExpressionTypeChecker.TryAssertBooleanConstantAsType((IEdmBooleanConstantExpression)expression, type, out discoveredErrors);
					}
					case EdmValueKind.Collection:
					case EdmValueKind.Enum:
					case EdmValueKind.Null:
					case EdmValueKind.Structured:
					{
						edmError = new EdmError[1];
						edmError[0] = new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType);
						discoveredErrors = edmError;
						return false;
					}
					case EdmValueKind.DateTimeOffset:
					{
						return ExpressionTypeChecker.TryAssertDateTimeOffsetConstantAsType((IEdmDateTimeOffsetConstantExpression)expression, type, out discoveredErrors);
					}
					case EdmValueKind.DateTime:
					{
						return ExpressionTypeChecker.TryAssertDateTimeConstantAsType((IEdmDateTimeConstantExpression)expression, type, out discoveredErrors);
					}
					case EdmValueKind.Decimal:
					{
						return ExpressionTypeChecker.TryAssertDecimalConstantAsType((IEdmDecimalConstantExpression)expression, type, out discoveredErrors);
					}
					case EdmValueKind.Floating:
					{
						return ExpressionTypeChecker.TryAssertFloatingConstantAsType((IEdmFloatingConstantExpression)expression, type, out discoveredErrors);
					}
					case EdmValueKind.Guid:
					{
						return ExpressionTypeChecker.TryAssertGuidConstantAsType((IEdmGuidConstantExpression)expression, type, out discoveredErrors);
					}
					case EdmValueKind.Integer:
					{
						return ExpressionTypeChecker.TryAssertIntegerConstantAsType((IEdmIntegerConstantExpression)expression, type, out discoveredErrors);
					}
					case EdmValueKind.String:
					{
						return ExpressionTypeChecker.TryAssertStringConstantAsType((IEdmStringConstantExpression)expression, type, out discoveredErrors);
					}
					case EdmValueKind.Time:
					{
						return ExpressionTypeChecker.TryAssertTimeConstantAsType((IEdmTimeConstantExpression)expression, type, out discoveredErrors);
					}
					default:
					{
						edmError = new EdmError[1];
						edmError[0] = new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType);
						discoveredErrors = edmError;
						return false;
					}
				}
			}
			else
			{
				EdmError[] edmErrorArray = new EdmError[1];
				edmErrorArray[0] = new EdmError(expression.Location(), EdmErrorCode.PrimitiveConstantExpressionNotValidForNonPrimitiveType, Strings.EdmModel_Validator_Semantic_PrimitiveConstantExpressionNotValidForNonPrimitiveType);
				discoveredErrors = edmErrorArray;
				return false;
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:75,代码来源:ExpressionTypeChecker.cs

示例13: TestTypeMatch

        private static bool TestTypeMatch(this IEdmTypeReference expressionType, IEdmTypeReference assertedType, EdmLocation location, out IEnumerable<EdmError> discoveredErrors)
        {
            if (!TestNullabilityMatch(expressionType, assertedType, location, out discoveredErrors))
            {
                return false;
            }

            // A bad type matches anything (so as to avoid generating spurious errors).
            if (expressionType.TypeKind() == EdmTypeKind.None || expressionType.IsBad())
            {
                discoveredErrors = Enumerable.Empty<EdmError>();
                return true;
            }

            if (expressionType.IsPrimitive() && assertedType.IsPrimitive())
            {
                if (!expressionType.PrimitiveKind().PromotesTo(assertedType.AsPrimitive().PrimitiveKind()))
                {
                    discoveredErrors = new EdmError[] { new EdmError(location, EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindCannotPromoteToAssertedType(expressionType.FullName(), assertedType.FullName())) };
                    return false;
                }
            }
            else
            {
                if (!expressionType.Definition.IsEquivalentTo(assertedType.Definition))
                {
                    discoveredErrors = new EdmError[] { new EdmError(location, EdmErrorCode.ExpressionNotValidForTheAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionNotValidForTheAssertedType) };
                    return false;
                }
            }

            discoveredErrors = Enumerable.Empty<EdmError>();
            return true;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:34,代码来源:ExpressionTypeChecker.cs


注:本文中的IEdmTypeReference.IsPrimitive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。