本文整理汇总了C#中IEdmTypeReference.AsStructured方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.AsStructured方法的具体用法?C# IEdmTypeReference.AsStructured怎么用?C# IEdmTypeReference.AsStructured使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.AsStructured方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryCastRecordAsType
internal static bool TryCastRecordAsType(this IEdmRecordExpression expression, IEdmTypeReference type, IEdmType context, bool matchExactly, out IEnumerable<EdmError> discoveredErrors)
{
EdmUtil.CheckArgumentNull(expression, "expression");
EdmUtil.CheckArgumentNull(type, "type");
if (!type.IsStructured())
{
discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.RecordExpressionNotValidForNonStructuredType, Edm.Strings.EdmModel_Validator_Semantic_RecordExpressionNotValidForNonStructuredType) };
return false;
}
HashSetInternal<string> foundProperties = new HashSetInternal<string>();
List<EdmError> errors = new List<EdmError>();
IEdmStructuredTypeReference structuredType = type.AsStructured();
foreach (IEdmProperty typeProperty in structuredType.StructuredDefinition().Properties())
{
IEdmPropertyConstructor expressionProperty = expression.Properties.FirstOrDefault(p => p.Name == typeProperty.Name);
if (expressionProperty == null)
{
errors.Add(new EdmError(expression.Location(), EdmErrorCode.RecordExpressionMissingRequiredProperty, Edm.Strings.EdmModel_Validator_Semantic_RecordExpressionMissingProperty(typeProperty.Name)));
}
else
{
IEnumerable<EdmError> recursiveErrors;
if (!expressionProperty.Value.TryCast(typeProperty.Type, context, matchExactly, out recursiveErrors))
{
foreach (EdmError error in recursiveErrors)
{
errors.Add(error);
}
}
foundProperties.Add(typeProperty.Name);
}
}
if (!structuredType.IsOpen())
{
foreach (IEdmPropertyConstructor property in expression.Properties)
{
if (!foundProperties.Contains(property.Name))
{
errors.Add(new EdmError(expression.Location(), EdmErrorCode.RecordExpressionHasExtraProperties, Edm.Strings.EdmModel_Validator_Semantic_RecordExpressionHasExtraProperties(property.Name)));
}
}
}
if (errors.FirstOrDefault() != null)
{
discoveredErrors = errors;
return false;
}
discoveredErrors = Enumerable.Empty<EdmError>();
return true;
}
示例2: VerifyComplexType
/// <summary>
/// Verifies that complex type is valid against the expected type.
/// </summary>
/// <param name="expectedTypeReference">The expected type reference.</param>
/// <param name="payloadType">The payload type.</param>
/// <param name="failIfNotRelated">true if the method should fail if the <paramref name="payloadType"/> doesn't match the <paramref name="expectedTypeReference"/>;
/// false if the method should just return in that case.</param>
/// <remarks>
/// The method verifies that the <paramref name="payloadType"/> equals to or derives from the <paramref name="expectedTypeReference"/>
/// and always fails in other cases.
/// </remarks>
private static void VerifyComplexType(IEdmTypeReference expectedTypeReference, IEdmType payloadType, bool failIfNotRelated)
{
Debug.Assert(expectedTypeReference != null, "expectedTypeReference != null");
Debug.Assert(payloadType != null, "payloadType != null");
// Note that we compare the type definitions, since we want to ignore nullability (the payload type doesn't specify nullability).
IEdmStructuredType structuredExpectedType = expectedTypeReference.AsStructured().StructuredDefinition();
IEdmStructuredType structuredPayloadType = (IEdmStructuredType)payloadType;
if (!EdmLibraryExtensions.IsAssignableFrom(structuredExpectedType, structuredPayloadType))
{
if (failIfNotRelated)
{
// And now the generic one when the types are not related at all.
throw new ODataException(Strings.ValidationUtils_IncompatibleType(structuredPayloadType.ODataFullName(), structuredExpectedType.ODataFullName()));
}
}
}
示例3: VerifyComplexType
private static void VerifyComplexType(IEdmTypeReference expectedTypeReference, IEdmType payloadType, bool failIfNotRelated)
{
IEdmStructuredType thisType = expectedTypeReference.AsStructured().StructuredDefinition();
IEdmStructuredType otherType = (IEdmStructuredType) payloadType;
if (!thisType.IsEquivalentTo(otherType))
{
if (thisType.IsAssignableFrom(otherType))
{
throw new ODataException(Microsoft.Data.OData.Strings.ReaderValidationUtils_DerivedComplexTypesAreNotAllowed(thisType.ODataFullName(), otherType.ODataFullName()));
}
if (failIfNotRelated)
{
throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_IncompatibleType(otherType.ODataFullName(), thisType.ODataFullName()));
}
}
}
示例4: VerifyComplexType
/// <summary>
/// Verifies that complex type is valid against the expected type.
/// </summary>
/// <param name="expectedTypeReference">The expected type reference.</param>
/// <param name="payloadType">The payload type.</param>
/// <param name="failIfNotRelated">true if the method should fail if the <paramref name="payloadType"/> doesn't match the <paramref name="expectedTypeReference"/>;
/// false if the method should just return in that case.</param>
/// <remarks>
/// The method verifies that the <paramref name="payloadType"/> is not a derived complex type of the <paramref name="expectedTypeReference"/>
/// and always fails in that case.
/// </remarks>
private static void VerifyComplexType(IEdmTypeReference expectedTypeReference, IEdmType payloadType, bool failIfNotRelated)
{
Debug.Assert(expectedTypeReference != null, "expectedTypeReference != null");
Debug.Assert(payloadType != null, "payloadType != null");
// Note that we compare the type definitions, since we want to ignore nullability (the payload type doesn't specify nullability).
IEdmStructuredType structuredExpectedType = expectedTypeReference.AsStructured().StructuredDefinition();
IEdmStructuredType structuredPayloadType = (IEdmStructuredType)payloadType;
if (!structuredExpectedType.IsEquivalentTo(structuredPayloadType))
{
// We want a specific error message in case of inheritance.
if (EdmLibraryExtensions.IsAssignableFrom(structuredExpectedType, structuredPayloadType))
{
// We don't allow type inheritance on complex types.
throw new ODataException(Strings.ReaderValidationUtils_DerivedComplexTypesAreNotAllowed(structuredExpectedType.ODataFullName(), structuredPayloadType.ODataFullName()));
}
if (failIfNotRelated)
{
// And now the generic one when the types are not related at all.
throw new ODataException(Strings.ValidationUtils_IncompatibleType(structuredPayloadType.ODataFullName(), structuredExpectedType.ODataFullName()));
}
}
}
示例5: TryAssertRecordAsType
internal static bool TryAssertRecordAsType(this IEdmRecordExpression expression, IEdmTypeReference type, out IEnumerable<EdmError> discoveredErrors)
{
IEnumerable<EdmError> edmErrors = null;
EdmUtil.CheckArgumentNull<IEdmRecordExpression>(expression, "expression");
EdmUtil.CheckArgumentNull<IEdmTypeReference>(type, "type");
if (type.IsStructured())
{
HashSetInternal<string> strs = new HashSetInternal<string>();
List<EdmError> edmErrors1 = new List<EdmError>();
IEdmStructuredTypeReference edmStructuredTypeReference = type.AsStructured();
IEnumerator<IEdmProperty> enumerator = edmStructuredTypeReference.StructuredDefinition().Properties().GetEnumerator();
using (enumerator)
{
Func<IEdmPropertyConstructor, bool> func = null;
while (enumerator.MoveNext())
{
IEdmProperty current = enumerator.Current;
IEnumerable<IEdmPropertyConstructor> properties = expression.Properties;
if (func == null)
{
func = (IEdmPropertyConstructor p) => p.Name == current.Name;
}
IEdmPropertyConstructor edmPropertyConstructor = properties.FirstOrDefault<IEdmPropertyConstructor>(func);
if (edmPropertyConstructor != null)
{
if (!edmPropertyConstructor.Value.TryAssertType(current.Type, out edmErrors))
{
IEnumerator<EdmError> enumerator1 = edmErrors.GetEnumerator();
using (enumerator1)
{
while (enumerator1.MoveNext())
{
EdmError edmError = enumerator1.Current;
edmErrors1.Add(edmError);
}
}
}
strs.Add(current.Name);
}
else
{
edmErrors1.Add(new EdmError(expression.Location(), EdmErrorCode.RecordExpressionMissingRequiredProperty, Strings.EdmModel_Validator_Semantic_RecordExpressionMissingProperty(current.Name)));
}
}
}
if (!edmStructuredTypeReference.IsOpen())
{
foreach (IEdmPropertyConstructor property in expression.Properties)
{
if (strs.Contains(property.Name))
{
continue;
}
edmErrors1.Add(new EdmError(expression.Location(), EdmErrorCode.RecordExpressionHasExtraProperties, Strings.EdmModel_Validator_Semantic_RecordExpressionHasExtraProperties(property.Name)));
}
}
if (edmErrors1.FirstOrDefault<EdmError>() == null)
{
discoveredErrors = Enumerable.Empty<EdmError>();
return true;
}
else
{
discoveredErrors = edmErrors1;
return false;
}
}
else
{
EdmError[] edmErrorArray = new EdmError[1];
edmErrorArray[0] = new EdmError(expression.Location(), EdmErrorCode.RecordExpressionNotValidForNonStructuredType, Strings.EdmModel_Validator_Semantic_RecordExpressionNotValidForNonStructuredType);
discoveredErrors = edmErrorArray;
return false;
}
}