本文整理汇总了C#中IEdmTypeReference.IsODataComplexTypeKind方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.IsODataComplexTypeKind方法的具体用法?C# IEdmTypeReference.IsODataComplexTypeKind怎么用?C# IEdmTypeReference.IsODataComplexTypeKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.IsODataComplexTypeKind方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanConvertTo
internal static bool CanConvertTo(IEdmTypeReference sourceReference, IEdmTypeReference targetReference)
{
if (sourceReference.IsEquivalentTo(targetReference))
{
return true;
}
if (targetReference.IsODataComplexTypeKind() || targetReference.IsODataEntityTypeKind())
{
return ((IEdmStructuredType) targetReference.Definition).IsAssignableFrom(((IEdmStructuredType) sourceReference.Definition));
}
if (IsOpenPropertyType(targetReference))
{
return true;
}
IEdmPrimitiveTypeReference type = sourceReference.AsPrimitiveOrNull();
IEdmPrimitiveTypeReference reference2 = targetReference.AsPrimitiveOrNull();
return (((type != null) && (reference2 != null)) && MetadataUtilsCommon.CanConvertPrimitiveTypeTo(type.PrimitiveDefinition(), reference2.PrimitiveDefinition()));
}
示例2: 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()));
}
}
}
}
}
示例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: 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: 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;
}
示例6: CanConvertTo
internal static bool CanConvertTo(SingleValueNode sourceNodeOrNull, IEdmTypeReference sourceReference, IEdmTypeReference targetReference)
{
Debug.Assert(sourceReference != null, "sourceReference != null");
Debug.Assert(targetReference != null, "targetReference != null");
//// Copy of the ResourceQueryParser.ExpressionParser.IsCompatibleWith method.
if (sourceReference.IsEquivalentTo(targetReference))
{
return true;
}
if (targetReference.IsODataComplexTypeKind() || targetReference.IsODataEntityTypeKind())
{
// for structured types, use IsAssignableFrom
return EdmLibraryExtensions.IsAssignableFrom(
(IEdmStructuredType)targetReference.Definition,
(IEdmStructuredType)sourceReference.Definition);
}
//// This rule stops the parser from considering nullable types as incompatible
//// with non-nullable types. We have however implemented this rule because we just
//// access underlying rules. C# requires an explicit .Value access, and EDM has no
//// nullablity on types and (at the model level) implements null propagation.
////
//// if (sourceReference.IsNullable && !targetReference.IsNullable)
//// {
//// return false;
//// }
if (sourceReference.IsEnum() && targetReference.IsEnum())
{
if (sourceReference.Definition.IsEquivalentTo(targetReference.Definition))
{
return targetReference.IsNullable() || (!sourceReference.IsNullable());
}
return false;
}
IEdmPrimitiveTypeReference sourcePrimitiveTypeReference = sourceReference.AsPrimitiveOrNull();
IEdmPrimitiveTypeReference targetPrimitiveTypeReference = targetReference.AsPrimitiveOrNull();
if (sourcePrimitiveTypeReference == null || targetPrimitiveTypeReference == null)
{
return false;
}
return MetadataUtilsCommon.CanConvertPrimitiveTypeTo(sourceNodeOrNull, sourcePrimitiveTypeReference.PrimitiveDefinition(), targetPrimitiveTypeReference.PrimitiveDefinition());
}
示例7: 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()));
}
}
}
}
}
示例8: 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()));
}
}
}
}
示例9: SetEpmValue
/// <summary>
/// Sets the value read from EPM to a property on an entry.
/// </summary>
/// <param name="targetList">The target list, which is a list of properties (on entry or complex value).</param>
/// <param name="targetTypeReference">The type of the value on which to set the property (can be entity or complex).</param>
/// <param name="epmInfo">The EPM info for the mapping for which the value was read.</param>
/// <param name="propertyValue">The property value read, if the value was specified as null then this should be null,
/// if the value was missing the method should not be called at all.
/// For primitive properties this should be the string value, for all other properties this should be the exact value type.</param>
protected void SetEpmValue(
IList targetList,
IEdmTypeReference targetTypeReference,
EntityPropertyMappingInfo epmInfo,
object propertyValue)
{
Debug.Assert(epmInfo != null, "epmInfo != null");
Debug.Assert(targetTypeReference != null, "targetTypeReference != null");
Debug.Assert(targetList != null, "targetList != null");
Debug.Assert(
targetTypeReference.IsODataEntityTypeKind() || targetTypeReference.IsODataComplexTypeKind(),
"Only entity and complex types can have an EPM value set on them.");
this.SetEpmValueForSegment(
epmInfo,
0,
targetTypeReference.AsStructuredOrNull(),
(List<ODataProperty>)targetList,
propertyValue);
}
示例10: 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;
}
示例11: ReadProperty
/// <summary>
/// Reads a property.
/// </summary>
/// <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>
/// <param name="epmPresent">Whether any EPM mappings exist.</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(IEdmTypeReference expectedPropertyTypeReference, ODataNullValueBehaviorKind nullValueReadBehaviorKind, bool epmPresent)
{
Debug.Assert(
expectedPropertyTypeReference == null || expectedPropertyTypeReference.IsODataPrimitiveTypeKind() ||
expectedPropertyTypeReference.IsODataComplexTypeKind() || expectedPropertyTypeReference.IsNonEntityODataCollectionTypeKind(),
"Only primitive, complex and collection types can be read by this method.");
this.AssertXmlCondition(XmlNodeType.Element);
Debug.Assert(this.UseServerFormatBehavior || this.XmlReader.NamespaceEquals(this.XmlReader.ODataNamespace), "Property elements must be in the OData namespace (unless we are running in WCF DS server format mode).");
this.XmlReader.AssertNotBuffering();
ODataProperty property = new ODataProperty();
string propertyName = this.XmlReader.LocalName;
ValidationUtils.ValidatePropertyName(propertyName);
property.Name = propertyName;
object propertyValue = this.ReadNonEntityValueImplementation(
expectedPropertyTypeReference,
/*duplicatePropertyNamesChecker*/ null,
/*collectionValidator*/ null,
nullValueReadBehaviorKind == ODataNullValueBehaviorKind.Default,
epmPresent);
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;
}