本文整理汇总了C#中IEdmTypeReference.AsActualTypeReference方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.AsActualTypeReference方法的具体用法?C# IEdmTypeReference.AsActualTypeReference怎么用?C# IEdmTypeReference.AsActualTypeReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.AsActualTypeReference方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsEquivalentTo
/// <summary>
/// Returns true if the compared type reference is semantically equivalent to this type reference.
/// Schema types (<see cref="IEdmSchemaType"/>) are compared by their object refs.
/// </summary>
/// <param name="thisType">Type reference being compared.</param>
/// <param name="otherType">Type referenced being compared to.</param>
/// <returns>Equivalence of the two type references.</returns>
public static bool IsEquivalentTo(this IEdmTypeReference thisType, IEdmTypeReference otherType)
{
if (thisType == otherType)
{
return true;
}
if (thisType == null || otherType == null)
{
return false;
}
thisType = thisType.AsActualTypeReference();
otherType = otherType.AsActualTypeReference();
EdmTypeKind typeKind = thisType.TypeKind();
if (typeKind != otherType.TypeKind())
{
return false;
}
if (typeKind == EdmTypeKind.Primitive)
{
return ((IEdmPrimitiveTypeReference)thisType).IsEquivalentTo((IEdmPrimitiveTypeReference)otherType);
}
else
{
return thisType.IsNullable == otherType.IsNullable &&
thisType.Definition.IsEquivalentTo(otherType.Definition);
}
}
示例2: TryCast
/// <summary>
/// Determines if the type of an expression is compatible with the provided type
/// </summary>
/// <param name="expression">The expression to assert the type of.</param>
/// <param name="type">The type to assert the expression as.</param>
/// <param name="context">The context paths are to be evaluated in.</param>
/// <param name="matchExactly">A value indicating whether the expression must match the asserted type exactly, or simply be compatible.</param>
/// <param name="discoveredErrors">Errors produced if the expression does not match the specified type.</param>
/// <returns>A value indicating whether the expression is valid for the given type or not.</returns>
/// <remarks>If the expression has an associated type, this function will check that it matches the expected type and stop looking further.
/// If an expression claims a type, it must be validated that the type is valid for the expression. If the expression does not claim a type
/// this method will attempt to check the validity of the expression itself with the asserted type.</remarks>
public static bool TryCast(this IEdmExpression expression, IEdmTypeReference type, IEdmType context, bool matchExactly, out IEnumerable<EdmError> discoveredErrors)
{
EdmUtil.CheckArgumentNull(expression, "expression");
type = type.AsActualTypeReference();
// If we don't have a type to assert this passes vacuously.
if (type == null || type.TypeKind() == EdmTypeKind.None)
{
discoveredErrors = Enumerable.Empty<EdmError>();
return true;
}
switch (expression.ExpressionKind)
{
case EdmExpressionKind.IntegerConstant:
case EdmExpressionKind.StringConstant:
case EdmExpressionKind.BinaryConstant:
case EdmExpressionKind.BooleanConstant:
case EdmExpressionKind.DateTimeOffsetConstant:
case EdmExpressionKind.DecimalConstant:
case EdmExpressionKind.FloatingConstant:
case EdmExpressionKind.GuidConstant:
case EdmExpressionKind.DurationConstant:
case EdmExpressionKind.DateConstant:
case EdmExpressionKind.TimeOfDayConstant:
IEdmPrimitiveValue primitiveValue = (IEdmPrimitiveValue)expression;
if (primitiveValue.Type != null)
{
return TestTypeReferenceMatch(primitiveValue.Type, type, expression.Location(), matchExactly, out discoveredErrors);
}
return TryCastPrimitiveAsType(primitiveValue, type, out discoveredErrors);
case EdmExpressionKind.Null:
return TryCastNullAsType((IEdmNullExpression)expression, type, out discoveredErrors);
case EdmExpressionKind.Path:
case EdmExpressionKind.PropertyPath:
case EdmExpressionKind.NavigationPropertyPath:
return TryCastPathAsType((IEdmPathExpression)expression, type, context, matchExactly, out discoveredErrors);
case EdmExpressionKind.OperationApplication:
IEdmApplyExpression applyExpression = (IEdmApplyExpression)expression;
if (applyExpression.AppliedOperation != null)
{
IEdmOperation operation = applyExpression.AppliedOperation as IEdmOperation;
if (operation != null)
{
return TestTypeReferenceMatch(operation.ReturnType, type, expression.Location(), matchExactly, out discoveredErrors);
}
}
// If we don't have the applied function we just assume that it will work.
discoveredErrors = Enumerable.Empty<EdmError>();
return true;
case EdmExpressionKind.If:
return TryCastIfAsType((IEdmIfExpression)expression, type, context, matchExactly, out discoveredErrors);
case EdmExpressionKind.IsType:
return TestTypeReferenceMatch(EdmCoreModel.Instance.GetBoolean(false), type, expression.Location(), matchExactly, out discoveredErrors);
case EdmExpressionKind.Record:
IEdmRecordExpression recordExpression = (IEdmRecordExpression)expression;
if (recordExpression.DeclaredType != null)
{
return TestTypeReferenceMatch(recordExpression.DeclaredType, type, expression.Location(), matchExactly, out discoveredErrors);
}
return TryCastRecordAsType(recordExpression, type, context, matchExactly, out discoveredErrors);
case EdmExpressionKind.Collection:
IEdmCollectionExpression collectionExpression = (IEdmCollectionExpression)expression;
if (collectionExpression.DeclaredType != null)
{
return TestTypeReferenceMatch(collectionExpression.DeclaredType, type, expression.Location(), matchExactly, out discoveredErrors);
}
return TryCastCollectionAsType(collectionExpression, type, context, matchExactly, out discoveredErrors);
case EdmExpressionKind.Labeled:
return TryCast(((IEdmLabeledExpression)expression).Expression, type, context, matchExactly, out discoveredErrors);
case EdmExpressionKind.Cast:
return TestTypeReferenceMatch(((IEdmCastExpression)expression).Type, type, expression.Location(), matchExactly, out discoveredErrors);
case EdmExpressionKind.LabeledExpressionReference:
return TryCast(((IEdmLabeledExpressionReferenceExpression)expression).ReferencedLabeledExpression, type, out discoveredErrors);
default:
discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.ExpressionNotValidForTheAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionNotValidForTheAssertedType) };
return false;
}
}