本文整理汇总了C#中IEdmTypeReference.IsODataEnumTypeKind方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.IsODataEnumTypeKind方法的具体用法?C# IEdmTypeReference.IsODataEnumTypeKind怎么用?C# IEdmTypeReference.IsODataEnumTypeKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.IsODataEnumTypeKind方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}
}
}
}
示例3: 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;
}
示例4: 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)
{
Debug.Assert(
expectedItemTypeReference == null ||
expectedItemTypeReference.IsODataPrimitiveTypeKind() ||
expectedItemTypeReference.IsODataComplexTypeKind() ||
expectedItemTypeReference.IsODataEnumTypeKind() ||
expectedItemTypeReference.IsODataTypeDefinitionTypeKind(),
"If an expected type is specified, it must be a primitive, complex type, enum type or type definition.");
this.JsonReader.AssertNotBuffering();
object item = this.ReadNonEntityValue(
/*payloadTypeName*/ null,
expectedItemTypeReference,
this.duplicatePropertyNamesChecker,
collectionValidator,
/*validateNullValue*/ true,
/*isTopLevelPropertyValue*/ false,
/*insideComplexValue*/ false,
/*propertyName*/ null);
this.JsonReader.AssertNotBuffering();
return item;
}