/// <summary> /// Returns true if function signatures are semantically equivalent. /// Signature includes function name (<see cref="IEdmNamedElement"/>) and its parameter types. /// </summary> /// <param name="thisFunction">Reference to the calling object.</param> /// <param name="otherFunction">Function being compared to.</param> /// <returns>Equivalence of signatures of the two functions.</returns> internal static bool IsFunctionSignatureEquivalentTo(this IEdmFunctionBase thisFunction, IEdmFunctionBase otherFunction) { if (thisFunction == otherFunction) { return(true); } if (thisFunction.Name != otherFunction.Name) { return(false); } if (!thisFunction.ReturnType.IsEquivalentTo(otherFunction.ReturnType)) { return(false); } IEnumerator <IEdmFunctionParameter> otherFunctionParameterEnumerator = otherFunction.Parameters.GetEnumerator(); foreach (IEdmFunctionParameter parameter in thisFunction.Parameters) { otherFunctionParameterEnumerator.MoveNext(); if (!parameter.IsEquivalentTo(otherFunctionParameterEnumerator.Current)) { return(false); } } return(true); }
protected virtual void ProcessFunctionBase(IEdmFunctionBase functionBase) { if (functionBase.ReturnType != null) { this.VisitTypeReference(functionBase.ReturnType); } this.VisitFunctionParameters(functionBase.Parameters); }
public EdmFunctionParameter(IEdmFunctionBase declaringFunction, string name, IEdmTypeReference type, EdmFunctionParameterMode mode) : base(name) { EdmUtil.CheckArgumentNull <IEdmFunctionBase>(declaringFunction, "declaringFunction"); EdmUtil.CheckArgumentNull <string>(name, "name"); EdmUtil.CheckArgumentNull <IEdmTypeReference>(type, "type"); this.type = type; this.mode = mode; this.declaringFunction = declaringFunction; }
public EdmFunctionParameter(IEdmFunctionBase declaringFunction, string name, IEdmTypeReference type, EdmFunctionParameterMode mode) : base(name) { EdmUtil.CheckArgumentNull<IEdmFunctionBase>(declaringFunction, "declaringFunction"); EdmUtil.CheckArgumentNull<string>(name, "name"); EdmUtil.CheckArgumentNull<IEdmTypeReference>(type, "type"); this.type = type; this.mode = mode; this.declaringFunction = declaringFunction; }
/// <summary> /// Initializes a new instance of <see cref="EdmFunctionParameterFacade"/> class. /// </summary> /// <param name="serverFunctionParameter">The function parameter from the server-side model to wrap.</param> /// <param name="declaringFunctionFacade">The function import facade which this parameter belongs to.</param> /// <param name="modelFacade">The edm model facade this function import belongs to.</param> public EdmFunctionParameterFacade(IEdmFunctionParameter serverFunctionParameter, EdmFunctionImportFacade declaringFunctionFacade, EdmModelFacade modelFacade) { Debug.Assert(serverFunctionParameter != null, "serverFunctionParameter != null"); Debug.Assert(declaringFunctionFacade != null, "declaringFunctionFacade != null"); Debug.Assert(modelFacade != null, "modelFacade != null"); this.serverFunctionParameter = serverFunctionParameter; this.declaringFunction = declaringFunctionFacade; this.type = modelFacade.GetOrCreateEntityTypeFacadeOrReturnNonEntityServerType(serverFunctionParameter.Type.Definition).ToEdmTypeReference(serverFunctionParameter.Type.IsNullable); }
/// <summary> /// Initializes a new instance of <see cref="EdmFunctionParameterFacade"/> class. /// </summary> /// <param name="serverFunctionParameter">The function parameter from the server-side model to wrap.</param> /// <param name="declaringFunctionFacade">The function import facade which this parameter belongs to.</param> /// <param name="modelFacade">The edm model facade this function import belongs to.</param> public EdmFunctionParameterFacade(IEdmFunctionParameter serverFunctionParameter, EdmFunctionImportFacade declaringFunctionFacade, EdmModelFacade modelFacade) { Debug.Assert(serverFunctionParameter != null, "serverFunctionParameter != null"); Debug.Assert(declaringFunctionFacade != null, "declaringFunctionFacade != null"); Debug.Assert(modelFacade != null, "modelFacade != null"); this.serverFunctionParameter = serverFunctionParameter; this.declaringFunction = declaringFunctionFacade; this.type = modelFacade.GetOrCreateEntityTypeFacadeOrReturnNonEntityServerType(serverFunctionParameter.Type.Definition).ToEdmTypeReference(serverFunctionParameter.Type.IsNullable); }
protected virtual void ProcessFunctionBase(IEdmFunctionBase functionBase) { if (functionBase.ReturnType != null) { this.VisitTypeReference(functionBase.ReturnType); } // Do not visit vocabularyAnnotatable because functions and function imports are always going to be either a schema element or a container element and will be visited through those paths. this.VisitFunctionParameters(functionBase.Parameters); }
public static string ParameterizedName(IEdmFunctionBase function) { int index = 0; int parameterCount = function.Parameters.Count(); StringBuilder sb = new StringBuilder(); UnresolvedFunction unresolvedFunctionImport = function as UnresolvedFunction; if (unresolvedFunctionImport != null) { sb.Append(unresolvedFunctionImport.Namespace); sb.Append("/"); sb.Append(unresolvedFunctionImport.Name); return(sb.ToString()); } // If we have a function (rather than a function import), we want the parameterized name to include the namespace IEdmSchemaElement schemaFunction = function as IEdmSchemaElement; if (schemaFunction != null) { sb.Append(schemaFunction.Namespace); sb.Append("."); } sb.Append(function.Name); sb.Append("("); foreach (IEdmFunctionParameter parameter in function.Parameters) { string typeName = ""; if (parameter.Type.IsCollection()) { typeName = CsdlConstants.Value_Collection + "(" + parameter.Type.AsCollection().ElementType().FullName() + ")"; } else if (parameter.Type.IsEntityReference()) { typeName = CsdlConstants.Value_Ref + "(" + parameter.Type.AsEntityReference().EntityType().FullName() + ")"; } else { typeName = parameter.Type.FullName(); } sb.Append(typeName); index++; if (index < parameterCount) { sb.Append(", "); } } sb.Append(")"); return(sb.ToString()); }
public UnresolvedParameter(IEdmFunctionBase declaringFunction, string name, EdmLocation location) : base(new EdmError[] { new EdmError(location, EdmErrorCode.BadUnresolvedParameter, Strings.Bad_UnresolvedParameter(name)) }) { this.type = new Cache<UnresolvedParameter, IEdmTypeReference>(); string str = name; string empty = str; if (str == null) { empty = string.Empty; } this.name = empty; this.declaringFunction = declaringFunction; }
public UnresolvedParameter(IEdmFunctionBase declaringFunction, string name, EdmLocation location) : base(new EdmError[] { new EdmError(location, EdmErrorCode.BadUnresolvedParameter, Strings.Bad_UnresolvedParameter(name)) }) { this.type = new Cache <UnresolvedParameter, IEdmTypeReference>(); string str = name; string empty = str; if (str == null) { empty = string.Empty; } this.name = empty; this.declaringFunction = declaringFunction; }
internal static bool IsFunctionSignatureEquivalentTo(this IEdmFunctionBase thisFunction, IEdmFunctionBase otherFunction) { bool flag; if (thisFunction != otherFunction) { if (thisFunction.Name == otherFunction.Name) { if (thisFunction.ReturnType.IsEquivalentTo(otherFunction.ReturnType)) { IEnumerator <IEdmFunctionParameter> enumerator = otherFunction.Parameters.GetEnumerator(); IEnumerator <IEdmFunctionParameter> enumerator1 = thisFunction.Parameters.GetEnumerator(); using (enumerator1) { while (enumerator1.MoveNext()) { IEdmFunctionParameter current = enumerator1.Current; enumerator.MoveNext(); if (current.IsEquivalentTo(enumerator.Current)) { continue; } flag = false; return(flag); } return(true); } return(flag); } else { return(false); } } else { return(false); } } else { return(true); } }
public static string ParameterizedName(IEdmFunctionBase function) { string str; int num = 0; int num1 = function.Parameters.Count <IEdmFunctionParameter>(); StringBuilder stringBuilder = new StringBuilder(); IEdmSchemaElement edmSchemaElement = function as IEdmSchemaElement; if (edmSchemaElement != null) { stringBuilder.Append(edmSchemaElement.Namespace); stringBuilder.Append("."); } stringBuilder.Append(function.Name); stringBuilder.Append("("); foreach (IEdmFunctionParameter parameter in function.Parameters) { if (!parameter.Type.IsCollection()) { if (!parameter.Type.IsEntityReference()) { str = parameter.Type.FullName(); } else { str = string.Concat("Ref(", parameter.Type.AsEntityReference().EntityType().FullName(), ")"); } } else { str = string.Concat("Collection(", parameter.Type.AsCollection().ElementType().FullName(), ")"); } stringBuilder.Append(str); num++; if (num >= num1) { continue; } stringBuilder.Append(", "); } stringBuilder.Append(")"); return(stringBuilder.ToString()); }
public static bool TryAssertType(this IEdmExpression expression, IEdmTypeReference type, out IEnumerable <EdmError> discoveredErrors) { EdmError[] edmError; EdmUtil.CheckArgumentNull <IEdmExpression>(expression, "expression"); if (type == null || type.TypeKind() == EdmTypeKind.None) { discoveredErrors = Enumerable.Empty <EdmError>(); return(true); } else { EdmExpressionKind expressionKind = expression.ExpressionKind; switch (expressionKind) { case EdmExpressionKind.BinaryConstant: case EdmExpressionKind.BooleanConstant: case EdmExpressionKind.DateTimeConstant: case EdmExpressionKind.DateTimeOffsetConstant: case EdmExpressionKind.DecimalConstant: case EdmExpressionKind.FloatingConstant: case EdmExpressionKind.GuidConstant: case EdmExpressionKind.IntegerConstant: case EdmExpressionKind.StringConstant: case EdmExpressionKind.TimeConstant: { IEdmPrimitiveValue edmPrimitiveValue = (IEdmPrimitiveValue)expression; if (edmPrimitiveValue.Type == null) { return(edmPrimitiveValue.TryAssertPrimitiveAsType(type, out discoveredErrors)); } else { return(edmPrimitiveValue.Type.TestTypeMatch(type, expression.Location(), out discoveredErrors)); } } case EdmExpressionKind.Null: { return(((IEdmNullExpression)expression).TryAssertNullAsType(type, out discoveredErrors)); } case EdmExpressionKind.Record: { IEdmRecordExpression edmRecordExpression = (IEdmRecordExpression)expression; if (edmRecordExpression.DeclaredType == null) { return(edmRecordExpression.TryAssertRecordAsType(type, out discoveredErrors)); } else { return(edmRecordExpression.DeclaredType.TestTypeMatch(type, expression.Location(), out discoveredErrors)); } } case EdmExpressionKind.Collection: { IEdmCollectionExpression edmCollectionExpression = (IEdmCollectionExpression)expression; if (edmCollectionExpression.DeclaredType == null) { return(edmCollectionExpression.TryAssertCollectionAsType(type, out discoveredErrors)); } else { return(edmCollectionExpression.DeclaredType.TestTypeMatch(type, expression.Location(), out discoveredErrors)); } } case EdmExpressionKind.Path: { return(((IEdmPathExpression)expression).TryAssertPathAsType(type, out discoveredErrors)); } case EdmExpressionKind.ParameterReference: case EdmExpressionKind.FunctionReference: case EdmExpressionKind.PropertyReference: case EdmExpressionKind.ValueTermReference: case EdmExpressionKind.EntitySetReference: case EdmExpressionKind.EnumMemberReference: { edmError = new EdmError[1]; edmError[0] = new EdmError(expression.Location(), EdmErrorCode.ExpressionNotValidForTheAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionNotValidForTheAssertedType); discoveredErrors = edmError; return(false); } case EdmExpressionKind.If: { return(((IEdmIfExpression)expression).TryAssertIfAsType(type, out discoveredErrors)); } case EdmExpressionKind.AssertType: { return(((IEdmAssertTypeExpression)expression).Type.TestTypeMatch(type, expression.Location(), out discoveredErrors)); } case EdmExpressionKind.IsType: { return(EdmCoreModel.Instance.GetBoolean(false).TestTypeMatch(type, expression.Location(), out discoveredErrors)); } case EdmExpressionKind.FunctionApplication: { IEdmApplyExpression edmApplyExpression = (IEdmApplyExpression)expression; if (edmApplyExpression.AppliedFunction != null) { IEdmFunctionBase appliedFunction = edmApplyExpression.AppliedFunction as IEdmFunctionBase; if (appliedFunction != null) { return(appliedFunction.ReturnType.TestTypeMatch(type, expression.Location(), out discoveredErrors)); } } discoveredErrors = Enumerable.Empty <EdmError>(); return(true); } case EdmExpressionKind.LabeledExpressionReference: { return(((IEdmLabeledExpressionReferenceExpression)expression).ReferencedLabeledExpression.TryAssertType(type, out discoveredErrors)); } case EdmExpressionKind.Labeled: { return(((IEdmLabeledExpression)expression).Expression.TryAssertType(type, out discoveredErrors)); } default: { edmError = new EdmError[1]; edmError[0] = new EdmError(expression.Location(), EdmErrorCode.ExpressionNotValidForTheAssertedType, Strings.EdmModel_Validator_Semantic_ExpressionNotValidForTheAssertedType); discoveredErrors = edmError; return(false); } } } }
public UnresolvedParameter(IEdmFunctionBase declaringFunction, string name, EdmLocation location) : base(new EdmError[] { new EdmError(location, EdmErrorCode.BadUnresolvedParameter, Edm.Strings.Bad_UnresolvedParameter(name)) }) { this.name = name ?? string.Empty; this.declaringFunction = declaringFunction; }
/// <summary> /// Returns true if function signatures are semantically equivalent. /// Signature includes function name (<see cref="IEdmNamedElement"/>) and its parameter types. /// </summary> /// <param name="thisFunction">Reference to the calling object.</param> /// <param name="otherFunction">Function being compared to.</param> /// <returns>Equivalence of signatures of the two functions.</returns> internal static bool IsFunctionSignatureEquivalentTo(this IEdmFunctionBase thisFunction, IEdmFunctionBase otherFunction) { if (thisFunction == otherFunction) { return true; } if (thisFunction.Name != otherFunction.Name) { return false; } if (!thisFunction.ReturnType.IsEquivalentTo(otherFunction.ReturnType)) { return false; } IEnumerator<IEdmFunctionParameter> otherFunctionParameterEnumerator = otherFunction.Parameters.GetEnumerator(); foreach (IEdmFunctionParameter parameter in thisFunction.Parameters) { otherFunctionParameterEnumerator.MoveNext(); if (!parameter.IsEquivalentTo(otherFunctionParameterEnumerator.Current)) { return false; } } return true; }
public EdmFunctionParameter(IEdmFunctionBase declaringFunction, string name, IEdmTypeReference type) : this(declaringFunction, name, type, (EdmFunctionParameterMode)1) { }
/// <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 TryAssertType(this IEdmExpression expression, IEdmTypeReference type, IEdmType context, bool matchExactly, out IEnumerable <EdmError> discoveredErrors) { EdmUtil.CheckArgumentNull(expression, "expression"); // 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.DateTimeConstant: case EdmExpressionKind.DateTimeOffsetConstant: case EdmExpressionKind.DecimalConstant: case EdmExpressionKind.FloatingConstant: case EdmExpressionKind.GuidConstant: case EdmExpressionKind.TimeConstant: IEdmPrimitiveValue primitiveValue = (IEdmPrimitiveValue)expression; if (primitiveValue.Type != null) { return(TestTypeReferenceMatch(primitiveValue.Type, type, expression.Location(), matchExactly, out discoveredErrors)); } return(TryAssertPrimitiveAsType(primitiveValue, type, out discoveredErrors)); case EdmExpressionKind.Null: return(TryAssertNullAsType((IEdmNullExpression)expression, type, out discoveredErrors)); case EdmExpressionKind.Path: return(TryAssertPathAsType((IEdmPathExpression)expression, type, context, matchExactly, out discoveredErrors)); case EdmExpressionKind.FunctionApplication: IEdmApplyExpression applyExpression = (IEdmApplyExpression)expression; if (applyExpression.AppliedFunction != null) { IEdmFunctionBase function = applyExpression.AppliedFunction as IEdmFunctionBase; if (function != null) { return(TestTypeReferenceMatch(function.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(TryAssertIfAsType((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(TryAssertRecordAsType(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(TryAssertCollectionAsType(collectionExpression, type, context, matchExactly, out discoveredErrors)); case EdmExpressionKind.Labeled: return(TryAssertType(((IEdmLabeledExpression)expression).Expression, type, context, matchExactly, out discoveredErrors)); case EdmExpressionKind.AssertType: return(TestTypeReferenceMatch(((IEdmAssertTypeExpression)expression).Type, type, expression.Location(), matchExactly, out discoveredErrors)); case EdmExpressionKind.LabeledExpressionReference: return(TryAssertType(((IEdmLabeledExpressionReferenceExpression)expression).ReferencedLabeledExpression, type, out discoveredErrors)); default: discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.ExpressionNotValidForTheAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionNotValidForTheAssertedType) }; return(false); } }
internal static bool IsFunctionSignatureEquivalentTo(this IEdmFunctionBase thisFunction, IEdmFunctionBase otherFunction) { bool flag; if (thisFunction != otherFunction) { if (thisFunction.Name == otherFunction.Name) { if (thisFunction.ReturnType.IsEquivalentTo(otherFunction.ReturnType)) { IEnumerator<IEdmFunctionParameter> enumerator = otherFunction.Parameters.GetEnumerator(); IEnumerator<IEdmFunctionParameter> enumerator1 = thisFunction.Parameters.GetEnumerator(); using (enumerator1) { while (enumerator1.MoveNext()) { IEdmFunctionParameter current = enumerator1.Current; enumerator.MoveNext(); if (current.IsEquivalentTo(enumerator.Current)) { continue; } flag = false; return flag; } return true; } return flag; } else { return false; } } else { return false; } } else { return true; } }
public EdmFunctionParameter(IEdmFunctionBase declaringFunction, string name, IEdmTypeReference type) : this(declaringFunction, name, type, (EdmFunctionParameterMode)1) { }
/// <summary> /// Generates an action link following the OData URL conventions for the action <paramref name="action"/> and bound to the entity /// represented by <paramref name="entityContext"/>. /// </summary> /// <param name="entityContext">The <see cref="EntityInstanceContext"/> representing the entity for which the action link needs to be generated.</param> /// <param name="action">The action for which the action link needs to be generated.</param> /// <returns>The generated action link following OData URL conventions.</returns> public static Uri GenerateActionLink(this EntityInstanceContext entityContext, IEdmFunctionBase action) { if (entityContext == null) { throw Error.ArgumentNull("entityContext"); } if (action == null) { throw Error.ArgumentNull("action"); } IEdmFunctionParameter bindingParameter = action.Parameters.FirstOrDefault(); if (bindingParameter == null || !bindingParameter.Type.IsEntity()) { throw Error.Argument("action", SRResources.ActionNotBoundToEntity, action.Name); } return(GenerateActionLink(entityContext, bindingParameter.Type.FullName(), action.Name)); }
/// <summary> /// Generates an action link following the OData URL conventions for the action <paramref name="action"/> and bound to the entity /// represented by <paramref name="entityContext"/>. /// </summary> /// <param name="entityContext">The <see cref="EntityInstanceContext"/> representing the entity for which the action link needs to be generated.</param> /// <param name="action">The action for which the action link needs to be generated.</param> /// <returns>The generated action link following OData URL conventions.</returns> public static Uri GenerateActionLink(this EntityInstanceContext entityContext, IEdmFunctionBase action) { if (entityContext == null) { throw Error.ArgumentNull("entityContext"); } if (action == null) { throw Error.ArgumentNull("action"); } IEdmFunctionParameter bindingParameter = action.Parameters.FirstOrDefault(); if (bindingParameter == null || !bindingParameter.Type.IsEntity()) { throw Error.Argument("action", SRResources.ActionNotBoundToEntity, action.Name); } return GenerateActionLink(entityContext, bindingParameter.Type.FullName(), action.Name); }
public UnresolvedParameter(IEdmFunctionBase declaringFunction, string name, EdmLocation location) : base(new EdmError[] { new EdmError(location, EdmErrorCode.BadUnresolvedParameter, Edm.Strings.Bad_UnresolvedParameter(name)) }) { this.name = name ?? string.Empty; this.declaringFunction = declaringFunction; }