本文整理汇总了C#中IEdmTypeReference.IsNonEntityCollectionType方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.IsNonEntityCollectionType方法的具体用法?C# IEdmTypeReference.IsNonEntityCollectionType怎么用?C# IEdmTypeReference.IsNonEntityCollectionType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.IsNonEntityCollectionType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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()));
}
}
}
}
}
示例2: 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;
}
示例3: VerifyCollectionComplexItemType
/// <summary>
/// Verifies that in case of collection types, the item type is valid.
/// </summary>
/// <param name="expectedTypeReference">The expected type reference.</param>
/// <param name="payloadType">The payload type.</param>
/// <remarks>
/// This method verifies that item type is compatible with expected type.
/// </remarks>
private static void VerifyCollectionComplexItemType(IEdmTypeReference expectedTypeReference, IEdmType payloadType)
{
Debug.Assert(expectedTypeReference != null, "expectedTypeReference != null");
Debug.Assert(payloadType != null, "payloadType != null");
Debug.Assert(expectedTypeReference.IsNonEntityCollectionType(), "This method only works on atomic collections.");
Debug.Assert(payloadType.IsNonEntityCollectionType(), "This method only works on atomic collections.");
IEdmCollectionTypeReference collectionTypeReference = ValidationUtils.ValidateCollectionType(expectedTypeReference);
IEdmTypeReference expectedItemTypeReference = collectionTypeReference.GetCollectionItemType();
if (expectedItemTypeReference != null && expectedItemTypeReference.IsODataComplexTypeKind())
{
IEdmCollectionTypeReference payloadCollectionTypeReference = ValidationUtils.ValidateCollectionType(payloadType.ToTypeReference());
IEdmTypeReference payloadItemTypeReference = payloadCollectionTypeReference.GetCollectionItemType();
if (payloadItemTypeReference != null && payloadItemTypeReference.IsODataComplexTypeKind())
{
// Note that this method is called from both strict and lax code paths, so we must not fail if the types are not related.
VerifyComplexType(expectedItemTypeReference, payloadItemTypeReference.Definition, /* failIfNotRelated */ false);
}
}
}
示例4: 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 OData-Version.</param>
/// <param name="propertyName">The name of the property whose value is being read, if applicable (used for error reporting).</param>
/// <param name="isDynamicProperty">Indicates whether the property is dynamic or unknown.</param>
private static void ValidateNullValueAllowed(IEdmTypeReference expectedValueTypeReference, bool validateNullValue, IEdmModel model, string propertyName, bool? isDynamicProperty)
{
Debug.Assert(model != null, "For null validation, model is required.");
if (validateNullValue && expectedValueTypeReference != null)
{
Debug.Assert(
expectedValueTypeReference.IsODataPrimitiveTypeKind() ||
expectedValueTypeReference.IsODataTypeDefinitionTypeKind() ||
expectedValueTypeReference.IsODataEnumTypeKind() ||
expectedValueTypeReference.IsODataComplexTypeKind() ||
expectedValueTypeReference.IsNonEntityCollectionType(),
"Only primitive, type definition, Enum, complex and collection types are supported by this method.");
if (expectedValueTypeReference.IsODataPrimitiveTypeKind())
{
// COMPAT 55: WCF DS allows null values for non-nullable properties
// For now ODataLib will always fail on null value when it is to be reported for a non-nullable property
// We should add a knob since WCF DS might need the different behavior.
if (!expectedValueTypeReference.IsNullable)
{
ThrowNullValueForNonNullableTypeException(expectedValueTypeReference, propertyName);
}
}
else if (expectedValueTypeReference.IsODataEnumTypeKind())
{
if (!expectedValueTypeReference.IsNullable)
{
ThrowNullValueForNonNullableTypeException(expectedValueTypeReference, propertyName);
}
}
else if (expectedValueTypeReference.IsNonEntityCollectionType())
{
if (isDynamicProperty != true)
{
ThrowNullValueForNonNullableTypeException(expectedValueTypeReference, propertyName);
}
}
else if (expectedValueTypeReference.IsODataComplexTypeKind())
{
if (ValidationUtils.ShouldValidateComplexPropertyNullValue(model))
{
IEdmComplexTypeReference complexTypeReference = expectedValueTypeReference.AsComplex();
if (!complexTypeReference.IsNullable)
{
ThrowNullValueForNonNullableTypeException(expectedValueTypeReference, propertyName);
}
}
}
}
}
示例5: ValidateCollectionType
/// <summary>
/// Validates that the <paramref name="typeReference"/> represents a collection type.
/// </summary>
/// <param name="typeReference">The type reference to validate.</param>
/// <returns>The <see cref="IEdmCollectionTypeReference"/> instance representing the collection passed as <paramref name="typeReference"/>.</returns>
internal static IEdmCollectionTypeReference ValidateCollectionType(IEdmTypeReference typeReference)
{
IEdmCollectionTypeReference collectionTypeReference = typeReference.AsCollectionOrNull();
if (collectionTypeReference != null && !typeReference.IsNonEntityCollectionType())
{
throw new ODataException(Strings.ValidationUtils_InvalidCollectionTypeReference(typeReference.TypeKind()));
}
return collectionTypeReference;
}