本文整理汇总了C#中IEdmTypeReference.IsODataPrimitiveTypeKind方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.IsODataPrimitiveTypeKind方法的具体用法?C# IEdmTypeReference.IsODataPrimitiveTypeKind怎么用?C# IEdmTypeReference.IsODataPrimitiveTypeKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.IsODataPrimitiveTypeKind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeTargetTypeKind
private static EdmTypeKind ComputeTargetTypeKind(IEdmTypeReference expectedTypeReference, bool forEntityValue, string payloadTypeName, EdmTypeKind payloadTypeKind, ODataMessageReaderSettings messageReaderSettings, Func<EdmTypeKind> typeKindFromPayloadFunc)
{
EdmTypeKind kind;
bool flag = (messageReaderSettings.ReaderBehavior.TypeResolver != null) && (payloadTypeKind != EdmTypeKind.None);
if (((expectedTypeReference != null) && !flag) && (!expectedTypeReference.IsODataPrimitiveTypeKind() || !messageReaderSettings.DisablePrimitiveTypeConversion))
{
kind = expectedTypeReference.TypeKind();
}
else if (payloadTypeKind != EdmTypeKind.None)
{
if (!forEntityValue)
{
ValidationUtils.ValidateValueTypeKind(payloadTypeKind, payloadTypeName);
}
kind = payloadTypeKind;
}
else
{
kind = typeKindFromPayloadFunc();
}
if (ShouldValidatePayloadTypeKind(messageReaderSettings, expectedTypeReference, payloadTypeKind))
{
ValidationUtils.ValidateTypeKind(kind, expectedTypeReference.TypeKind(), payloadTypeName);
}
return kind;
}
示例2: BuiltInFunctionSignature
/// <summary>
/// Constructor.
/// </summary>
/// <param name="returnType">The return type of the function.</param>
/// <param name="argumentTypes">The argument types for this function signature.</param>
private BuiltInFunctionSignature(IEdmTypeReference returnType, params IEdmTypeReference[] argumentTypes)
: base(argumentTypes)
{
Debug.Assert(returnType != null, "returnType != null");
Debug.Assert(returnType.IsODataPrimitiveTypeKind(), "Only primitive values are supported as built-in function return types.");
this.returnType = returnType;
}
示例3: ValidateNullCollectionItem
/// <summary>
/// Validates a null collection item against the expected type.
/// </summary>
/// <param name="expectedItemType">The expected item type or null if no expected item type exists.</param>
/// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param>
internal static void ValidateNullCollectionItem(IEdmTypeReference expectedItemType, ODataWriterBehavior writerBehavior)
{
if (expectedItemType != null)
{
if (expectedItemType.IsODataPrimitiveTypeKind())
{
// WCF DS allows null values for non-nullable primitive types, so we need to check for a knob which enables this behavior.
// See the description of ODataWriterBehavior.AllowNullValuesForNonNullablePrimitiveTypes for more details.
if (!expectedItemType.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes)
{
throw new ODataException(Strings.ValidationUtils_NullCollectionItemForNonNullableType(expectedItemType.ODataFullName()));
}
}
}
}
示例4: ValidateMetadataType
/// <summary>
/// Validates that the (optional) <paramref name="typeReferenceFromMetadata"/> is the same as the (optional) <paramref name="typeReferenceFromValue"/>.
/// </summary>
/// <param name="typeReferenceFromMetadata">The (optional) type from the metadata definition (the expected type).</param>
/// <param name="typeReferenceFromValue">The (optional) type from the value (the actual type).</param>
/// <returns>The type as derived from the <paramref name="typeReferenceFromMetadata"/> and/or <paramref name="typeReferenceFromValue"/>.</returns>
private static IEdmTypeReference ValidateMetadataType(IEdmTypeReference typeReferenceFromMetadata, IEdmTypeReference typeReferenceFromValue)
{
if (typeReferenceFromMetadata == null)
{
// if we have no metadata information there is nothing to validate
return typeReferenceFromValue;
}
if (typeReferenceFromValue == null)
{
// derive the property type from the metadata
return typeReferenceFromMetadata;
}
// Make sure the kinds are the same
EdmTypeKind typeKind = typeReferenceFromMetadata.TypeKind();
ValidationUtils.ValidateTypeKind(typeReferenceFromValue.Definition, typeKind);
// Make sure the types are the same
if (typeReferenceFromValue.IsODataPrimitiveTypeKind())
{
// Primitive types must match exactly except for nullability
ValidationUtils.ValidateMetadataPrimitiveType(typeReferenceFromMetadata, typeReferenceFromValue);
}
else if (typeKind == EdmTypeKind.Entity)
{
ValidationUtils.ValidateEntityTypeIsAssignable((IEdmEntityTypeReference)typeReferenceFromMetadata, (IEdmEntityTypeReference)typeReferenceFromValue);
}
else
{
// Complex and collection types must match exactly
if (typeReferenceFromMetadata.ODataFullName() != typeReferenceFromValue.ODataFullName())
{
throw new ODataException(Strings.ValidationUtils_IncompatibleType(typeReferenceFromValue.ODataFullName(), typeReferenceFromMetadata.ODataFullName()));
}
}
return typeReferenceFromValue;
}
示例5: ReadCollectionItem
/// <summary>
/// Reads an item in the collection.
/// </summary>
/// <param name="expectedItemTypeReference">The expected type of the item to read.</param>
/// <param name="collectionValidator">The collection validator instance if no expected item type has been specified; otherwise null.</param>
/// <returns>The value of the collection item that was read; this can be an ODataComplexValue, a primitive value or 'null'.</returns>
/// <remarks>
/// Pre-Condition: The first node of the item in the collection
/// NOTE: this method will throw if the node is not
/// JsonNodeType.StartObject: for a complex item
/// JsonNodeType.PrimitiveValue: for a primitive item
/// Post-Condition: The reader is positioned on the first node of the next item or an EndArray node if there are no more items in the collection
/// </remarks>
internal object ReadCollectionItem(IEdmTypeReference expectedItemTypeReference, CollectionWithoutExpectedTypeValidator collectionValidator)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(
expectedItemTypeReference == null ||
expectedItemTypeReference.IsODataPrimitiveTypeKind() ||
expectedItemTypeReference.IsODataComplexTypeKind(),
"If an expected type is specified, it must be a primitive or complex type.");
this.JsonReader.AssertNotBuffering();
object item = this.ReadNonEntityValue(
expectedItemTypeReference,
this.duplicatePropertyNamesChecker,
collectionValidator,
/*validateNullValue*/ true);
this.JsonReader.AssertNotBuffering();
return item;
}
示例6: ValidateNullPropertyValue
/// <summary>
/// Validates that the expected property allows null value.
/// </summary>
/// <param name="expectedPropertyTypeReference">The expected property type or null if we don't have any.</param>
/// <param name="propertyName">The name of the property.</param>
/// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param>
/// <param name="model">The model to use to get the OData version.</param>
/// <param name="bypassValidation">Bypass the validation if it is true.</param>
internal static void ValidateNullPropertyValue(IEdmTypeReference expectedPropertyTypeReference, string propertyName, ODataWriterBehavior writerBehavior, IEdmModel model, bool bypassValidation = false)
{
Debug.Assert(writerBehavior != null, "writerBehavior != null");
Debug.Assert(model != null, "For null validation, model is required.");
if (bypassValidation)
{
return;
}
if (expectedPropertyTypeReference != null)
{
if (expectedPropertyTypeReference.IsNonEntityCollectionType())
{
throw new ODataException(Strings.WriterValidationUtils_CollectionPropertiesMustNotHaveNullValue(propertyName));
}
if (expectedPropertyTypeReference.IsODataPrimitiveTypeKind())
{
// WCF DS allows null values for non-nullable primitive types, so we need to check for a knob which enables this behavior.
// See the description of ODataWriterBehavior.AllowNullValuesForNonNullablePrimitiveTypes for more details.
if (!expectedPropertyTypeReference.IsNullable && !writerBehavior.AllowNullValuesForNonNullablePrimitiveTypes)
{
throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.ODataFullName()));
}
}
else if (expectedPropertyTypeReference.IsODataEnumTypeKind() && !expectedPropertyTypeReference.IsNullable)
{
throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.ODataFullName()));
}
else if (expectedPropertyTypeReference.IsStream())
{
throw new ODataException(Strings.WriterValidationUtils_StreamPropertiesMustNotHaveNullValue(propertyName));
}
else if (expectedPropertyTypeReference.IsODataComplexTypeKind())
{
if (ValidationUtils.ShouldValidateComplexPropertyNullValue(model))
{
IEdmComplexTypeReference complexTypeReference = expectedPropertyTypeReference.AsComplex();
if (!complexTypeReference.IsNullable)
{
throw new ODataException(Strings.WriterValidationUtils_NonNullablePropertiesMustNotHaveNullValue(propertyName, expectedPropertyTypeReference.ODataFullName()));
}
}
}
}
}
示例7: ReadProperty
/// <summary>
/// Reads a property.
/// </summary>
/// <param name="isTop">whether it is the top level</param>
/// <param name="expectedPropertyName">The expected property name to be read from the payload (or null if no expected property name was specified).</param>
/// <param name="expectedPropertyTypeReference">The expected type reference of the property value.</param>
/// <param name="nullValueReadBehaviorKind">Behavior to use when reading null value for the property.</param>
/// <returns>The ODataProperty representing the property in question; if null is returned from this method it means that the property is to be ignored.</returns>
/// <remarks>
/// Pre-Condition: XmlNodeType.Element - The XML element representing the property to read.
/// Note that the method does NOT check for the property name neither it resolves the property against metadata.
/// Post-Condition: Any - The node after the property.
/// </remarks>
private ODataProperty ReadProperty(
bool isTop,
string expectedPropertyName,
IEdmTypeReference expectedPropertyTypeReference,
ODataNullValueBehaviorKind nullValueReadBehaviorKind)
{
Debug.Assert(
expectedPropertyTypeReference == null || expectedPropertyTypeReference.IsODataPrimitiveTypeKind() || expectedPropertyTypeReference.IsODataEnumTypeKind() ||
expectedPropertyTypeReference.IsODataComplexTypeKind() || expectedPropertyTypeReference.IsNonEntityCollectionType(),
"Only primitive, Enum, complex and collection types can be read by this method.");
this.AssertXmlCondition(XmlNodeType.Element);
this.XmlReader.AssertNotBuffering();
ODataProperty property = new ODataProperty();
string propertyName = null;
if (!isTop)
{
propertyName = this.XmlReader.LocalName;
ValidationUtils.ValidatePropertyName(propertyName);
ReaderValidationUtils.ValidateExpectedPropertyName(expectedPropertyName, propertyName);
}
property.Name = propertyName;
object propertyValue = this.ReadNonEntityValueImplementation(
expectedPropertyTypeReference,
/*duplicatePropertyNamesChecker*/ null,
/*collectionValidator*/ null,
nullValueReadBehaviorKind == ODataNullValueBehaviorKind.Default,
propertyName);
if (nullValueReadBehaviorKind == ODataNullValueBehaviorKind.IgnoreValue && propertyValue == null)
{
property = null;
}
else
{
property.Value = propertyValue;
}
// Read past the end tag of the property or the start tag if the element is empty.
this.XmlReader.Read();
this.XmlReader.AssertNotBuffering();
return property;
}
示例8: ShouldValidatePayloadTypeKind
/// <summary>
/// Determines if the expect value type and the current settings mandate us to validate type kinds of payload values.
/// </summary>
/// <param name="messageReaderSettings">The message reader settings.</param>
/// <param name="expectedValueTypeReference">The expected type reference for the value infered from the model.</param>
/// <param name="payloadTypeKind">The type kind of the payload value.</param>
/// <returns>true if the payload value kind must be verified, false otherwise.</returns>
/// <remarks>This method deals with the strict versus lax behavior, as well as with the behavior when primitive type conversion is disabled.</remarks>
private static bool ShouldValidatePayloadTypeKind(ODataMessageReaderSettings messageReaderSettings, IEdmTypeReference expectedValueTypeReference, EdmTypeKind payloadTypeKind)
{
// If we have a type resolver, we always use the type returned by the resolver
// and use the expected type only for the resolution.
bool useExpectedTypeOnlyForTypeResolution = messageReaderSettings.ReaderBehavior.TypeResolver != null && payloadTypeKind != EdmTypeKind.None;
// Type kind validation must happen when
// - In strict mode
// - Target type is primitive and primitive type conversion is disabled
// In lax mode we don't want to validate type kinds, but the DisablePrimitiveTypeConversion overrides the lax mode behavior.
// If there's no expected type, then there's nothing to validate against (open property).
return expectedValueTypeReference != null &&
(!messageReaderSettings.DisableStrictMetadataValidation ||
useExpectedTypeOnlyForTypeResolution ||
(expectedValueTypeReference.IsODataPrimitiveTypeKind() && messageReaderSettings.DisablePrimitiveTypeConversion));
}
示例9: ValidateMetadataType
/// <summary>
/// Validates that the (optional) <paramref name="typeReferenceFromMetadata"/> is the same as the (optional) <paramref name="typeReferenceFromValue"/>.
/// </summary>
/// <param name="typeReferenceFromMetadata">The (optional) type from the metadata definition (the expected type).</param>
/// <param name="typeReferenceFromValue">The (optional) type from the value (the actual type).</param>
/// <returns>The type as derived from the <paramref name="typeReferenceFromMetadata"/> and/or <paramref name="typeReferenceFromValue"/>.</returns>
private static IEdmTypeReference ValidateMetadataType(IEdmTypeReference typeReferenceFromMetadata, IEdmTypeReference typeReferenceFromValue)
{
if (typeReferenceFromMetadata == null)
{
// if we have no metadata information there is nothing to validate
return typeReferenceFromValue;
}
if (typeReferenceFromValue == null)
{
// derive the property type from the metadata
return typeReferenceFromMetadata;
}
Debug.Assert(typeReferenceFromValue.TypeKind() == typeReferenceFromMetadata.TypeKind(), "typeReferenceFromValue.TypeKind() == typeReferenceFromMetadata.TypeKind()");
// Make sure the types are the same
if (typeReferenceFromValue.IsODataPrimitiveTypeKind())
{
// Primitive types must match exactly except for nullability
ValidationUtils.ValidateMetadataPrimitiveType(typeReferenceFromMetadata, typeReferenceFromValue);
}
else if (typeReferenceFromMetadata.IsEntity())
{
ValidationUtils.ValidateEntityTypeIsAssignable((IEdmEntityTypeReference)typeReferenceFromMetadata, (IEdmEntityTypeReference)typeReferenceFromValue);
}
else if (typeReferenceFromMetadata.IsComplex())
{
ValidationUtils.ValidateComplexTypeIsAssignable(typeReferenceFromMetadata.Definition as IEdmComplexType, typeReferenceFromValue.Definition as IEdmComplexType);
}
else if (typeReferenceFromMetadata.IsCollection())
{
// Collection types must match exactly.
if (!(typeReferenceFromMetadata.Definition.IsElementTypeEquivalentTo(typeReferenceFromValue.Definition)))
{
throw new ODataException(Strings.ValidationUtils_IncompatibleType(typeReferenceFromValue.ODataFullName(), typeReferenceFromMetadata.ODataFullName()));
}
}
else
{
// For other types, compare their full type name.
if (typeReferenceFromMetadata.ODataFullName() != typeReferenceFromValue.ODataFullName())
{
throw new ODataException(Strings.ValidationUtils_IncompatibleType(typeReferenceFromValue.ODataFullName(), typeReferenceFromMetadata.ODataFullName()));
}
}
return typeReferenceFromValue;
}
示例10: ComputeTargetTypeKind
/// <summary>
/// Computes the type kind to be used to read the payload from the expected type, the payload type and
/// possibly the payload shape.
/// </summary>
/// <param name="expectedTypeReference">The expected type reference used to read the payload value.</param>
/// <param name="forEntityValue">true when resolving a type name for an entity value; false for a non-entity value.</param>
/// <param name="payloadTypeName">The type name read from the payload.</param>
/// <param name="payloadTypeKind">The type kind of the payload value.</param>
/// <param name="messageReaderSettings">The message reader settings.</param>
/// <param name="typeKindFromPayloadFunc">A func to determine the type kind of the value by analyzing the payload data.</param>
/// <returns>The type kind to be used to read the payload.</returns>
private static EdmTypeKind ComputeTargetTypeKind(
IEdmTypeReference expectedTypeReference,
bool forEntityValue,
string payloadTypeName,
EdmTypeKind payloadTypeKind,
ODataMessageReaderSettings messageReaderSettings,
Func<EdmTypeKind> typeKindFromPayloadFunc)
{
Debug.Assert(messageReaderSettings != null, "messageReaderSettings != null");
Debug.Assert(typeKindFromPayloadFunc != null, "typeKindFromPayloadFunc != null");
// If we have a type resolver, we always use the type returned by the resolver
// and use the expected type only for the resolution.
bool useExpectedTypeOnlyForTypeResolution = messageReaderSettings.ReaderBehavior.TypeResolver != null && payloadTypeKind != EdmTypeKind.None;
// Determine the target type kind
// If the DisablePrimitiveTypeConversion is on, we must not infer the type kind from the expected type
// but instead we need to read it from the payload.
// This is necessary to correctly fail on complex/collection as well as to correctly read spatial values.
EdmTypeKind targetTypeKind;
if (expectedTypeReference != null &&
!useExpectedTypeOnlyForTypeResolution &&
(!expectedTypeReference.IsODataPrimitiveTypeKind() || !messageReaderSettings.DisablePrimitiveTypeConversion))
{
// If we have an expected type, use that.
targetTypeKind = expectedTypeReference.TypeKind();
}
else if (payloadTypeKind != EdmTypeKind.None)
{
Debug.Assert(
messageReaderSettings.ReaderBehavior.TypeResolver == null ||
messageReaderSettings.ReaderBehavior.FormatBehaviorKind == ODataBehaviorKind.WcfDataServicesClient,
"A custom type resolver is only supported in the client format behavior.");
// If we have a type kind based on the type name, use it.
if (!forEntityValue)
{
ValidationUtils.ValidateValueTypeKind(payloadTypeKind, payloadTypeName);
}
targetTypeKind = payloadTypeKind;
}
else
{
// If payloadTypeKind == EdmTypeKind.None, we could not determine the payload type kind
// because there was no type name in the payload; detect the type kind from the shape of the payload.
targetTypeKind = typeKindFromPayloadFunc();
}
Debug.Assert(targetTypeKind != EdmTypeKind.None, "We should have determined the target type kind by now.");
if (ShouldValidatePayloadTypeKind(messageReaderSettings, expectedTypeReference, payloadTypeKind))
{
ValidationUtils.ValidateTypeKind(targetTypeKind, expectedTypeReference.TypeKind(), payloadTypeName);
}
return targetTypeKind;
}
示例11: ValidateNullValueAllowed
private static void ValidateNullValueAllowed(IEdmTypeReference expectedValueTypeReference, bool validateNullValue, IEdmModel model)
{
if (validateNullValue && (expectedValueTypeReference != null))
{
if (expectedValueTypeReference.IsODataPrimitiveTypeKind())
{
if (!expectedValueTypeReference.IsNullable)
{
throw new ODataException(Microsoft.Data.OData.Strings.ReaderValidationUtils_NullValueForNonNullableType(expectedValueTypeReference.ODataFullName()));
}
}
else
{
if (expectedValueTypeReference.IsNonEntityODataCollectionTypeKind())
{
throw new ODataException(Microsoft.Data.OData.Strings.ReaderValidationUtils_NullValueForNonNullableType(expectedValueTypeReference.ODataFullName()));
}
if ((expectedValueTypeReference.IsODataComplexTypeKind() && ValidationUtils.ShouldValidateComplexPropertyNullValue(model)) && !expectedValueTypeReference.AsComplex().IsNullable)
{
throw new ODataException(Microsoft.Data.OData.Strings.ReaderValidationUtils_NullValueForNonNullableType(expectedValueTypeReference.ODataFullName()));
}
}
}
}
示例12: ShouldValidatePayloadTypeKind
private static bool ShouldValidatePayloadTypeKind(ODataMessageReaderSettings messageReaderSettings, IEdmTypeReference expectedValueTypeReference, EdmTypeKind payloadTypeKind)
{
bool flag = (messageReaderSettings.ReaderBehavior.TypeResolver != null) && (payloadTypeKind != EdmTypeKind.None);
if (expectedValueTypeReference == null)
{
return false;
}
return ((!messageReaderSettings.DisableStrictMetadataValidation || flag) || (expectedValueTypeReference.IsODataPrimitiveTypeKind() && messageReaderSettings.DisablePrimitiveTypeConversion));
}
示例13: CanPromoteTo
/// <summary>Promotes the specified expression to the given type if necessary.</summary>
/// <param name="sourceType">The actual argument type.</param>
/// <param name="targetType">The required type to promote to.</param>
/// <returns>True if the <paramref name="sourceType"/> could be promoted; otherwise false.</returns>
private static bool CanPromoteTo(IEdmTypeReference sourceType, IEdmTypeReference targetType)
{
Debug.Assert(targetType != null, "targetType != null");
Debug.Assert(sourceType == null || sourceType.IsODataPrimitiveTypeKind(), "Type promotion only supported for primitive types.");
Debug.Assert(targetType.IsODataPrimitiveTypeKind(), "Type promotion only supported for primitive types.");
if (sourceType == null)
{
// This indicates that a null literal or an open type has been specified.
// For null literals we can promote to the required target type if it is nullable
// TODO: review this once open types are supported.
return targetType.IsNullable;
}
if (sourceType.IsEquivalentTo(targetType))
{
return true;
}
if (CanConvertTo(sourceType, targetType))
{
return true;
}
// Allow promotion from nullable to non-nullable by directly accessing underlying value.
if (sourceType.IsNullable && targetType.IsODataValueType())
{
IEdmTypeReference nonNullableSourceType = sourceType.Definition.ToTypeReference(false);
if (CanConvertTo(nonNullableSourceType, targetType))
{
return true;
}
}
return false;
}
示例14: ValidateIsExpectedPrimitiveType
/// <summary>
/// Validates that a given primitive value is of the expected (primitive) type.
/// </summary>
/// <param name="value">The value to check.</param>
/// <param name="valuePrimitiveTypeReference">The primitive type reference for the value - some callers have this already, so we save the lookup here.</param>
/// <param name="expectedTypeReference">The expected type for the value.</param>
/// <param name="bypassValidation">Bypass the validation if it is true.</param>
/// <remarks>
/// Some callers have the primitive type reference already resolved (from the value type)
/// so this method is an optimized version to not lookup the primitive type reference again.
/// </remarks>
internal static void ValidateIsExpectedPrimitiveType(object value, IEdmPrimitiveTypeReference valuePrimitiveTypeReference, IEdmTypeReference expectedTypeReference, bool bypassValidation = false)
{
Debug.Assert(value != null, "value != null");
Debug.Assert(expectedTypeReference != null, "expectedTypeReference != null");
if (bypassValidation)
{
return;
}
if (valuePrimitiveTypeReference == null)
{
throw new ODataException(Strings.ValidationUtils_UnsupportedPrimitiveType(value.GetType().FullName));
}
Debug.Assert(valuePrimitiveTypeReference.IsEquivalentTo(EdmLibraryExtensions.GetPrimitiveTypeReference(value.GetType())), "The value and valuePrimitiveTypeReference don't match.");
if (!expectedTypeReference.IsODataPrimitiveTypeKind() && !expectedTypeReference.IsODataTypeDefinitionTypeKind())
{
// non-primitive type found for primitive value.
throw new ODataException(Strings.ValidationUtils_NonPrimitiveTypeForPrimitiveValue(expectedTypeReference.ODataFullName()));
}
ValidateMetadataPrimitiveType(expectedTypeReference, valuePrimitiveTypeReference);
}
示例15: ValidateNullValueAllowed
/// <summary>
/// Validates that the specified <paramref name="expectedValueTypeReference"/> allows null values.
/// </summary>
/// <param name="expectedValueTypeReference">The expected type for the value, or null if no such type is available.</param>
/// <param name="validateNullValue">true to validate the null value; otherwise false.</param>
/// <param name="model">The model to use to get the data service version.</param>
private static void ValidateNullValueAllowed(IEdmTypeReference expectedValueTypeReference, bool validateNullValue, IEdmModel model)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(model != null, "For null validation, model is required.");
if (validateNullValue && expectedValueTypeReference != null)
{
Debug.Assert(
expectedValueTypeReference.IsODataPrimitiveTypeKind() ||
expectedValueTypeReference.IsODataComplexTypeKind() ||
expectedValueTypeReference.IsNonEntityODataCollectionTypeKind(),
"Only primitive, complex and collection types are supported by this method.");
if (expectedValueTypeReference.IsODataPrimitiveTypeKind())
{
if (!expectedValueTypeReference.IsNullable)
{
throw new ODataException(Strings.ReaderValidationUtils_NullValueForNonNullableType(expectedValueTypeReference.ODataFullName()));
}
}
else if (expectedValueTypeReference.IsNonEntityODataCollectionTypeKind())
{
throw new ODataException(Strings.ReaderValidationUtils_NullValueForNonNullableType(expectedValueTypeReference.ODataFullName()));
}
else if (expectedValueTypeReference.IsODataComplexTypeKind())
{
if (ValidationUtils.ShouldValidateComplexPropertyNullValue(model))
{
IEdmComplexTypeReference complexTypeReference = expectedValueTypeReference.AsComplex();
if (!complexTypeReference.IsNullable)
{
throw new ODataException(Strings.ReaderValidationUtils_NullValueForNonNullableType(expectedValueTypeReference.ODataFullName()));
}
}
}
}
}