private XObject GenerateValueExpression(XNamespace ns, IEdmExpression expression) { // TODO: handle other than constant, other DataTypes XObject returnXObject = null; switch (expression.ExpressionKind) { case EdmExpressionKind.Null: returnXObject = new XElement(ns.GetName("Null")); break; case EdmExpressionKind.IntegerConstant: var integerConstantExpression = (IEdmIntegerConstantExpression)expression; returnXObject = new XAttribute("Int", integerConstantExpression.Value); break; case EdmExpressionKind.StringConstant: var stringConstantExpression = (IEdmStringConstantExpression)expression; returnXObject = new XAttribute("String", stringConstantExpression.Value); break; case EdmExpressionKind.Collection: returnXObject = this.GenerateCollectionExpression(ns, (IEdmCollectionExpression)expression); break; case EdmExpressionKind.Record: returnXObject = this.GenerateRecordExpression(ns, (IEdmRecordExpression)expression); break; default: throw new NotSupportedException(); } return returnXObject; }
public EdmPropertyValueBinding(IEdmProperty boundProperty, IEdmExpression value) { EdmUtil.CheckArgumentNull<IEdmProperty>(boundProperty, "boundProperty"); EdmUtil.CheckArgumentNull<IEdmExpression>(value, "value"); this.boundProperty = boundProperty; this.@value = value; }
public EdmPropertyReferenceExpression(IEdmExpression baseExpression, IEdmProperty referencedProperty) { EdmUtil.CheckArgumentNull<IEdmExpression>(baseExpression, "baseExpression"); EdmUtil.CheckArgumentNull<IEdmProperty>(referencedProperty, "referencedPropert"); this.baseExpression = baseExpression; this.referencedProperty = referencedProperty; }
public EdmLabeledExpression(string name, IEdmExpression expression) { EdmUtil.CheckArgumentNull<string>(name, "name"); EdmUtil.CheckArgumentNull<IEdmExpression>(expression, "expression"); this.name = name; this.expression = expression; }
public EdmApplyExpression(IEdmExpression appliedFunction, IEnumerable<IEdmExpression> arguments) { EdmUtil.CheckArgumentNull<IEdmExpression>(appliedFunction, "appliedFunction"); EdmUtil.CheckArgumentNull<IEnumerable<IEdmExpression>>(arguments, "arguments"); this.appliedFunction = appliedFunction; this.arguments = arguments; }
/// <summary> /// Initializes a new instance of the <see cref="EdmActionImport"/> class. /// </summary> /// <param name="container">The container.</param> /// <param name="name">The name.</param> /// <param name="action">The action.</param> /// <param name="entitySetExpression">The entity set expression.</param> public EdmActionImport(IEdmEntityContainer container, string name, IEdmAction action, IEdmExpression entitySetExpression) : base(container, action, name, entitySetExpression) { EdmUtil.CheckArgumentNull(action, "action"); this.Action = action; }
public EdmPropertyConstructor(string name, IEdmExpression value) { EdmUtil.CheckArgumentNull<string>(name, "name"); EdmUtil.CheckArgumentNull<IEdmExpression>(value, "value"); this.name = name; this.@value = value; }
public EdmIsTypeExpression(IEdmExpression operand, IEdmTypeReference type) { EdmUtil.CheckArgumentNull<IEdmExpression>(operand, "operand"); EdmUtil.CheckArgumentNull<IEdmTypeReference>(type, "type"); this.operand = operand; this.type = type; }
/// <summary> /// Initializes a new instance of the <see cref="EdmFunctionImport"/> class. /// </summary> /// <param name="container">The container.</param> /// <param name="name">The name.</param> /// <param name="function">The function.</param> /// <param name="entitySetExpression">The entity set expression.</param> /// <param name="includeInServiceDocument">The value indicates if the function is to be include in the service document or not.</param> public EdmFunctionImport(IEdmEntityContainer container, string name, IEdmFunction function, IEdmExpression entitySetExpression, bool includeInServiceDocument) : base(container, function, name, entitySetExpression) { EdmUtil.CheckArgumentNull(function, "function"); this.Function = function; this.IncludeInServiceDocument = includeInServiceDocument; }
public EdmValueTermReferenceExpression(IEdmExpression baseExpression, IEdmValueTerm term, string qualifier) { EdmUtil.CheckArgumentNull<IEdmExpression>(baseExpression, "baseExpression"); EdmUtil.CheckArgumentNull<IEdmValueTerm>(term, "term"); this.baseExpression = baseExpression; this.term = term; this.qualifier = qualifier; }
public EdmIfExpression(IEdmExpression testExpression, IEdmExpression trueExpression, IEdmExpression falseExpression) { EdmUtil.CheckArgumentNull<IEdmExpression>(testExpression, "testExpression"); EdmUtil.CheckArgumentNull<IEdmExpression>(trueExpression, "trueExpression"); EdmUtil.CheckArgumentNull<IEdmExpression>(falseExpression, "falseExpression"); this.testExpression = testExpression; this.trueExpression = trueExpression; this.falseExpression = falseExpression; }
public EdmFunctionImport(IEdmEntityContainer container, string name, IEdmTypeReference returnType, IEdmExpression entitySet, bool isSideEffecting, bool isComposable, bool isBindable) : base(name, returnType) { EdmUtil.CheckArgumentNull<IEdmEntityContainer>(container, "container"); EdmUtil.CheckArgumentNull<string>(name, "name"); this.container = container; this.entitySet = entitySet; this.isSideEffecting = isSideEffecting; this.isComposable = isComposable; this.isBindable = isBindable; }
/// <summary> /// Initializes a new instance of <see cref="EdmOperationImport"/> class. /// </summary> /// <param name="container">An <see cref="IEdmEntityContainer"/> containing this operation import.</param> /// <param name="operation">The operation of the import.</param> /// <param name="name">Name of the operation import.</param> /// <param name="entitySet">An entity set containing entities returned by this operation import. /// The two expression kinds supported are <see cref="IEdmEntitySetReferenceExpression"/> and <see cref="IEdmPathExpression"/>.</param> protected EdmOperationImport( IEdmEntityContainer container, IEdmOperation operation, string name, IEdmExpression entitySet) : base(name) { EdmUtil.CheckArgumentNull(container, "container"); EdmUtil.CheckArgumentNull(operation, this.OperationArgumentNullParameterName()); this.Container = container; this.Operation = operation; this.EntitySet = entitySet; }
/// <summary> /// Resolves an IEdmExpression to an IEdmEntitySet. /// </summary> /// <param name="expression">Expression to resolve.</param> /// <returns>The resolved EntitySet.</returns> internal static IEdmEntitySet ResolveEntitySetFromExpression(IEdmExpression expression) { if (expression == null) { return null; } switch (expression.ExpressionKind) { case EdmExpressionKind.EntitySetReference: return ((IEdmEntitySetReferenceExpression)expression).ReferencedEntitySet; default: // TODO: we should support all the other options throw new NotSupportedException( ODataErrorStrings.Nodes_NonStaticEntitySetExpressionsAreNotSupportedInThisRelease); } }
public virtual EdmFunctionImport AddFunctionImport(string name, IEdmTypeReference returnType, IEdmExpression entitySet, bool sideEffecting, bool composable, bool bindable) { EdmFunctionImport edmFunctionImport = new EdmFunctionImport(this, name, returnType, entitySet, sideEffecting, composable, bindable); this.AddElement(edmFunctionImport); return(edmFunctionImport); }
/// <summary> /// Initializes a new instance of the <see cref="EdmValueAnnotation"/> class. /// </summary> /// <param name="target">Element the annotation applies to.</param> /// <param name="term">Term bound by the annotation.</param> /// <param name="qualifier">Qualifier used to discriminate between multiple bindings of the same property or type.</param> /// <param name="value">Expression producing the value of the annotation.</param> public EdmValueAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, string qualifier, IEdmExpression value) : base(target, term, qualifier) { EdmUtil.CheckArgumentNull(value, "value"); this.value = value; }
public CustomPropertyValueBinding(IEdmProperty boundProperty, IEdmExpression value) { this.boundProperty = boundProperty; this.value = value; }
/// <summary> /// Gets stored IEdmAnnotations from a IEdmModel that correspond to an IEdm object and converts them to an enumerable /// of OdcmAnnotations /// </summary> /// <param name="model">An IEdmModel which contains annotations and IEdm Objects</param> /// <param name="e">An object contained within the IEdmModel, such as an IEdmMethod</param> /// <returns> /// An empty enumerable of annotations for objects which lack annotations (or cannot be annotated in EDM), or an /// enumerable of converted annotations /// </returns> public static IEnumerable <OdcmVocabularyAnnotation> GetOdcmAnnotations(IEdmModel model, object e) { // Only annotatable types will have annotations; return an empty list if (!(e is IEdmVocabularyAnnotatable)) { yield break; } var annotatable = (IEdmVocabularyAnnotatable)e; // We must use the model to obtain annotations var annotations = model.FindVocabularyAnnotations(annotatable); foreach (var annotation in annotations) { // Perform the mapping from IEdmAnnotation types to OcdmAnnotations // Mapping name and name space is the simplest piece OdcmVocabularyAnnotation odcmAnnotation = new OdcmVocabularyAnnotation { Name = annotation.Term.Name, Namespace = annotation.Term.Namespace }; // Vocabulary elements are registered when we have parsed their model and cached it // Unmapped elements are either invalid vocabulary terms (mispelled or otherwise) or have not been registered if (VocabularyElementRegistered(odcmAnnotation)) { var elementType = _registeredVocabularyTypes[odcmAnnotation.Namespace][odcmAnnotation.Name]; // We have a delayedValue that will get us to the corresponding type of the annotation if (elementType.SchemaElementKind == EdmSchemaElementKind.Term && elementType is IEdmTerm) { var term = (IEdmTerm)elementType; var valueType = term.Type; var valueAnnotation = annotation as IEdmVocabularyAnnotation; if (valueAnnotation == null) { throw new InvalidOperationException("Unexpected non-delayedValue annotation"); } IEdmExpression valueExpression = valueAnnotation.Value; var result = MapToClr(valueType, valueExpression); if (result == null) { continue; } odcmAnnotation.Value = result; yield return(odcmAnnotation); } else { throw new InvalidOperationException( string.Format( "Cannot return annotation values for EDM element types that are not ValueTerms. Type was {0} for element name {1}", elementType.SchemaElementKind, elementType.Name)); } } } }
/// <summary> /// Initializes a new instance of the <see cref="EdmFunctionImport"/> class. /// </summary> /// <param name="container">The container.</param> /// <param name="name">The name.</param> /// <param name="function">The function.</param> /// <param name="entitySetExpression">The entity set expression.</param> /// <param name="includeInServiceDocument">The value indicates if the function is to be include in the service document or not.</param> public EdmFunctionImport(IEdmEntityContainer container, string name, IEdmFunction function, IEdmExpression entitySetExpression, bool includeInServiceDocument) : base(container, function, name, entitySetExpression) { EdmUtil.CheckArgumentNull(function, "function"); this.Function = function; this.IncludeInServiceDocument = includeInServiceDocument; }
private IEdmVocabularyAnnotation CreateAndAttachValueAnnotation(IEdmVocabularyAnnotatable target, IEdmValueTerm term, IEdmExpression value, string qualifier) { var annotation = new EdmAnnotation( target, term, qualifier, value); // ?? Unnatural API ((EdmModel)this.baseModel).AddVocabularyAnnotation(annotation); return annotation; }
/// <summary> /// Evaluates an expression with no value context. /// </summary> /// <typeparam name="T">The CLR type of the value to be returned.</typeparam> /// <param name="expression">Expression to evaluate. The expression must not contain paths, because no context for evaluating a path is supplied.</param> /// <returns>The value that results from evaluating the expression in the context of the supplied value.</returns> public T EvaluateToClrValue <T>(IEdmExpression expression) { IEdmValue edmValue = this.Evaluate(expression); return(this.edmToClrConverter.AsClrValue <T>(edmValue)); }
/// <summary> /// Creates and adds a function import to this entity container. /// </summary> /// <param name="name">Name of the function import.</param> /// <param name="function">The function of the specified function import.</param> /// <param name="entitySet">An entity set containing entities returned by this function import. /// The expression kind supported is <see cref="IEdmPathExpression"/>.</param> /// <param name="includeInServiceDocument">A value indicating whether this function import will be in the service document.</param> /// <returns>Created operation import.</returns> public virtual EdmOperationImport AddFunctionImport(string name, IEdmFunction function, IEdmExpression entitySet, bool includeInServiceDocument) { EdmOperationImport functionImport = new EdmFunctionImport(this, name, function, entitySet, includeInServiceDocument); this.AddElement(functionImport); return(functionImport); }
/// <summary> /// Initializes a new instance of the <see cref="EdmActionImport"/> class. /// </summary> /// <param name="container">The container.</param> /// <param name="name">The name.</param> /// <param name="action">The action.</param> /// <param name="entitySetExpression">The entity set expression.</param> public EdmActionImport(IEdmEntityContainer container, string name, IEdmAction action, IEdmExpression entitySetExpression) : base(container, action, name, entitySetExpression) { EdmUtil.CheckArgumentNull(action, "action"); this.Action = action; }
protected virtual void ProcessExpression(IEdmExpression expression) { }
public void VisitExpression(IEdmExpression expression) { EdmExpressionKind expressionKind = expression.ExpressionKind; switch (expressionKind) { case EdmExpressionKind.None: { this.ProcessExpression(expression); return; } case EdmExpressionKind.BinaryConstant: { this.ProcessBinaryConstantExpression((IEdmBinaryConstantExpression)expression); return; } case EdmExpressionKind.BooleanConstant: { this.ProcessBooleanConstantExpression((IEdmBooleanConstantExpression)expression); return; } case EdmExpressionKind.DateTimeConstant: { this.ProcessDateTimeConstantExpression((IEdmDateTimeConstantExpression)expression); return; } case EdmExpressionKind.DateTimeOffsetConstant: { this.ProcessDateTimeOffsetConstantExpression((IEdmDateTimeOffsetConstantExpression)expression); return; } case EdmExpressionKind.DecimalConstant: { this.ProcessDecimalConstantExpression((IEdmDecimalConstantExpression)expression); return; } case EdmExpressionKind.FloatingConstant: { this.ProcessFloatingConstantExpression((IEdmFloatingConstantExpression)expression); return; } case EdmExpressionKind.GuidConstant: { this.ProcessGuidConstantExpression((IEdmGuidConstantExpression)expression); return; } case EdmExpressionKind.IntegerConstant: { this.ProcessIntegerConstantExpression((IEdmIntegerConstantExpression)expression); return; } case EdmExpressionKind.StringConstant: { this.ProcessStringConstantExpression((IEdmStringConstantExpression)expression); return; } case EdmExpressionKind.TimeConstant: { this.ProcessTimeConstantExpression((IEdmTimeConstantExpression)expression); return; } case EdmExpressionKind.Null: { this.ProcessNullConstantExpression((IEdmNullExpression)expression); return; } case EdmExpressionKind.Record: { this.ProcessRecordExpression((IEdmRecordExpression)expression); return; } case EdmExpressionKind.Collection: { this.ProcessCollectionExpression((IEdmCollectionExpression)expression); return; } case EdmExpressionKind.Path: { this.ProcessPathExpression((IEdmPathExpression)expression); return; } case EdmExpressionKind.ParameterReference: { this.ProcessParameterReferenceExpression((IEdmParameterReferenceExpression)expression); return; } case EdmExpressionKind.FunctionReference: { this.ProcessFunctionReferenceExpression((IEdmFunctionReferenceExpression)expression); return; } case EdmExpressionKind.PropertyReference: { this.ProcessPropertyReferenceExpression((IEdmPropertyReferenceExpression)expression); return; } case EdmExpressionKind.ValueTermReference: { this.ProcessPropertyReferenceExpression((IEdmPropertyReferenceExpression)expression); return; } case EdmExpressionKind.EntitySetReference: { this.ProcessEntitySetReferenceExpression((IEdmEntitySetReferenceExpression)expression); return; } case EdmExpressionKind.EnumMemberReference: { this.ProcessEnumMemberReferenceExpression((IEdmEnumMemberReferenceExpression)expression); return; } case EdmExpressionKind.If: { this.ProcessIfExpression((IEdmIfExpression)expression); return; } case EdmExpressionKind.AssertType: { this.ProcessAssertTypeExpression((IEdmAssertTypeExpression)expression); return; } case EdmExpressionKind.IsType: { this.ProcessIsTypeExpression((IEdmIsTypeExpression)expression); return; } case EdmExpressionKind.FunctionApplication: { this.ProcessFunctionApplicationExpression((IEdmApplyExpression)expression); return; } case EdmExpressionKind.LabeledExpressionReference: { this.ProcessLabeledExpressionReferenceExpression((IEdmLabeledExpressionReferenceExpression)expression); return; } case EdmExpressionKind.Labeled: { this.ProcessLabeledExpression((IEdmLabeledExpression)expression); return; } } throw new InvalidOperationException(Strings.UnknownEnumVal_ExpressionKind(expression.ExpressionKind)); }
/// <summary> /// Creates and adds an action import to this entity container. /// </summary> /// <param name="name">Name of the action import.</param> /// <param name="action">Action that the action import is importing to the container.</param> /// <param name="entitySet">An entity set containing entities returned by this action import. /// The expression kind supported is <see cref="IEdmPathExpression"/>.</param> /// <returns>Created action import.</returns> public virtual EdmActionImport AddActionImport(string name, IEdmAction action, IEdmExpression entitySet) { EdmActionImport actionImport = new EdmActionImport(this, name, action, entitySet); this.AddElement(actionImport); return(actionImport); }
public void VisitExpression(IEdmExpression expression) { switch (expression.ExpressionKind) { case EdmExpressionKind.Cast: this.ProcessCastExpression((IEdmCastExpression)expression); break; case EdmExpressionKind.BinaryConstant: this.ProcessBinaryConstantExpression((IEdmBinaryConstantExpression)expression); break; case EdmExpressionKind.BooleanConstant: this.ProcessBooleanConstantExpression((IEdmBooleanConstantExpression)expression); break; case EdmExpressionKind.Collection: this.ProcessCollectionExpression((IEdmCollectionExpression)expression); break; case EdmExpressionKind.DateConstant: this.ProcessDateConstantExpression((IEdmDateConstantExpression)expression); break; case EdmExpressionKind.DateTimeOffsetConstant: this.ProcessDateTimeOffsetConstantExpression((IEdmDateTimeOffsetConstantExpression)expression); break; case EdmExpressionKind.DecimalConstant: this.ProcessDecimalConstantExpression((IEdmDecimalConstantExpression)expression); break; case EdmExpressionKind.EnumMember: this.ProcessEnumMemberExpression((IEdmEnumMemberExpression)expression); break; case EdmExpressionKind.FloatingConstant: this.ProcessFloatingConstantExpression((IEdmFloatingConstantExpression)expression); break; case EdmExpressionKind.FunctionApplication: this.ProcessFunctionApplicationExpression((IEdmApplyExpression)expression); break; case EdmExpressionKind.GuidConstant: this.ProcessGuidConstantExpression((IEdmGuidConstantExpression)expression); break; case EdmExpressionKind.If: this.ProcessIfExpression((IEdmIfExpression)expression); break; case EdmExpressionKind.IntegerConstant: this.ProcessIntegerConstantExpression((IEdmIntegerConstantExpression)expression); break; case EdmExpressionKind.IsType: this.ProcessIsTypeExpression((IEdmIsTypeExpression)expression); break; case EdmExpressionKind.LabeledExpressionReference: this.ProcessLabeledExpressionReferenceExpression((IEdmLabeledExpressionReferenceExpression)expression); break; case EdmExpressionKind.Labeled: this.ProcessLabeledExpression((IEdmLabeledExpression)expression); break; case EdmExpressionKind.Null: this.ProcessNullConstantExpression((IEdmNullExpression)expression); break; case EdmExpressionKind.Path: this.ProcessPathExpression((IEdmPathExpression)expression); break; case EdmExpressionKind.PropertyPath: this.ProcessPropertyPathExpression((IEdmPathExpression)expression); break; case EdmExpressionKind.NavigationPropertyPath: this.ProcessNavigationPropertyPathExpression((IEdmPathExpression)expression); break; case EdmExpressionKind.Record: this.ProcessRecordExpression((IEdmRecordExpression)expression); break; case EdmExpressionKind.StringConstant: this.ProcessStringConstantExpression((IEdmStringConstantExpression)expression); break; case EdmExpressionKind.TimeOfDayConstant: this.ProcessTimeOfDayConstantExpression((IEdmTimeOfDayConstantExpression)expression); break; case EdmExpressionKind.DurationConstant: this.ProcessDurationConstantExpression((IEdmDurationConstantExpression)expression); break; case EdmExpressionKind.None: this.ProcessExpression(expression); break; default: throw new InvalidOperationException(Edm.Strings.UnknownEnumVal_ExpressionKind(expression.ExpressionKind)); } }
/// <summary> /// Evaluates an expression in the context of a value. /// </summary> /// <typeparam name="T">The CLR type of the value to be returned.</typeparam> /// <param name="expression">Expression to evaluate.</param> /// <param name="context">Value to use as context in evaluating the expression.</param> /// <returns>The value that results from evaluating the expression in the context of the supplied value.</returns> public T EvaluateToClrValue <T>(IEdmExpression expression, IEdmStructuredValue context) { IEdmValue edmValue = this.Evaluate(expression, context); return(this.edmToClrConverter.AsClrValue <T>(edmValue)); }
/// <summary> /// Adds the function and function import. /// </summary> /// <param name="container">The container.</param> /// <param name="model">The model.</param> /// <param name="name">The name.</param> /// <param name="returnType">Type of the return.</param> /// <param name="entitySet">The entity set.</param> /// <param name="isBound">if set to <c>true</c> [is bound].</param> /// <returns>Returns the function import created.</returns> public static EdmActionImport AddActionAndActionImport(this EdmEntityContainer container, EdmModel model, string name, IEdmTypeReference returnType, IEdmExpression entitySet, bool isBound) { EdmAction action = new EdmAction(container.Namespace, name, returnType, isBound, null); model.AddElement(action); return container.AddActionImport(name, action, entitySet); }
/// <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="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, out IEnumerable <EdmError> discoveredErrors) { return(TryCast(expression, type, null, false, out discoveredErrors)); }
public virtual EdmFunctionImport AddFunctionImport(string name, IEdmTypeReference returnType, IEdmExpression entitySet) { EdmFunctionImport edmFunctionImport = new EdmFunctionImport(this, name, returnType, entitySet); this.AddElement(edmFunctionImport); return(edmFunctionImport); }
/// <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); } }
private static EdmOperationImport CreateFunctionImport( FunctionConfiguration function, EdmEntityContainer container, IEdmTypeReference returnReference, IEdmExpression expression, IEdmPathExpression pathExpression) { EdmFunction operation = new EdmFunction( container.Namespace, function.Name, returnReference, function.IsBindable, pathExpression, function.IsComposable); return new EdmFunctionImport(container, function.Name, operation, expression, includeInServiceDocument: function.IncludeInServiceDocument); }
internal void WriteInlineExpression(IEdmExpression expression) { switch (expression.ExpressionKind) { case EdmExpressionKind.BinaryConstant: this.WriteRequiredAttribute(CsdlConstants.Attribute_Binary, ((IEdmBinaryConstantExpression)expression).Value, EdmValueWriter.BinaryAsXml); break; case EdmExpressionKind.BooleanConstant: this.WriteRequiredAttribute(CsdlConstants.Attribute_Bool, ((IEdmBooleanConstantExpression)expression).Value, EdmValueWriter.BooleanAsXml); break; case EdmExpressionKind.DateTimeOffsetConstant: this.WriteRequiredAttribute(CsdlConstants.Attribute_DateTimeOffset, ((IEdmDateTimeOffsetConstantExpression)expression).Value, EdmValueWriter.DateTimeOffsetAsXml); break; case EdmExpressionKind.DecimalConstant: this.WriteRequiredAttribute(CsdlConstants.Attribute_Decimal, ((IEdmDecimalConstantExpression)expression).Value, EdmValueWriter.DecimalAsXml); break; case EdmExpressionKind.FloatingConstant: this.WriteRequiredAttribute(CsdlConstants.Attribute_Float, ((IEdmFloatingConstantExpression)expression).Value, EdmValueWriter.FloatAsXml); break; case EdmExpressionKind.GuidConstant: this.WriteRequiredAttribute(CsdlConstants.Attribute_Guid, ((IEdmGuidConstantExpression)expression).Value, EdmValueWriter.GuidAsXml); break; case EdmExpressionKind.IntegerConstant: this.WriteRequiredAttribute(CsdlConstants.Attribute_Int, ((IEdmIntegerConstantExpression)expression).Value, EdmValueWriter.LongAsXml); break; case EdmExpressionKind.Path: this.WriteRequiredAttribute(CsdlConstants.Attribute_Path, ((IEdmPathExpression)expression).PathSegments, PathAsXml); break; case EdmExpressionKind.PropertyPath: this.WriteRequiredAttribute(CsdlConstants.Attribute_PropertyPath, ((IEdmPathExpression)expression).PathSegments, PathAsXml); break; case EdmExpressionKind.NavigationPropertyPath: this.WriteRequiredAttribute(CsdlConstants.Attribute_NavigationPropertyPath, ((IEdmPathExpression)expression).PathSegments, PathAsXml); break; case EdmExpressionKind.StringConstant: this.WriteRequiredAttribute(CsdlConstants.Attribute_String, ((IEdmStringConstantExpression)expression).Value, EdmValueWriter.StringAsXml); break; case EdmExpressionKind.DurationConstant: this.WriteRequiredAttribute(CsdlConstants.Attribute_Duration, ((IEdmDurationConstantExpression)expression).Value, EdmValueWriter.DurationAsXml); break; case EdmExpressionKind.DateConstant: this.WriteRequiredAttribute(CsdlConstants.Attribute_Date, ((IEdmDateConstantExpression)expression).Value, EdmValueWriter.DateAsXml); break; case EdmExpressionKind.TimeOfDayConstant: this.WriteRequiredAttribute(CsdlConstants.Attribute_TimeOfDay, ((IEdmTimeOfDayConstantExpression)expression).Value, EdmValueWriter.TimeOfDayAsXml); break; default: Debug.Assert(false, "Attempted to inline an expression that was not one of the expected inlineable types."); break; } }
public virtual EdmFunctionImport AddFunctionImport(string name, IEdmTypeReference returnType, IEdmExpression entitySet, bool sideEffecting, bool composable, bool bindable) { EdmFunctionImport edmFunctionImport = new EdmFunctionImport(this, name, returnType, entitySet, sideEffecting, composable, bindable); this.AddElement(edmFunctionImport); return edmFunctionImport; }
/// <summary> /// Gets the symbolic string of an annotated element. /// In the next breaking change, it's better to add a property into <see cref="IEdmVocabularyAnnotatable"/>. /// </summary> /// <param name="annotatedElement">The annotatable element.</param> /// <returns>null or a symbolic string.</returns> public static string GetSymbolicString(this IEdmVocabularyAnnotatable annotatedElement) { IEdmSchemaElement schemaElement = annotatedElement as IEdmSchemaElement; if (schemaElement != null) { // EntityType, ComplexType, EnumType, TypeDefinition if (schemaElement.SchemaElementKind == EdmSchemaElementKind.TypeDefinition) { IEdmType edmType = (IEdmType)schemaElement; switch (edmType.TypeKind) { case EdmTypeKind.Complex: return("ComplexType"); case EdmTypeKind.Entity: return("EntityType"); case EdmTypeKind.Enum: return("EnumType"); case EdmTypeKind.TypeDefinition: return("TypeDefinition"); default: return(null); } } else { // Action, Function, Term, EntityContainer return(schemaElement.SchemaElementKind.ToString()); } } IEdmEntityContainerElement containerElement = annotatedElement as IEdmEntityContainerElement; if (containerElement != null) { // ActionImport, FunctionImport, EntitySet, Singleton return(containerElement.ContainerElementKind.ToString()); } IEdmProperty property = annotatedElement as IEdmProperty; if (property != null) { // NavigationProperty, Property switch (property.PropertyKind) { case EdmPropertyKind.Navigation: return("NavigationProperty"); case EdmPropertyKind.Structural: return("Property"); default: return(null); } } IEdmExpression expression = annotatedElement as IEdmExpression; if (expression != null) { switch (expression.ExpressionKind) { case EdmExpressionKind.FunctionApplication: return("Apply"); case EdmExpressionKind.IsType: return("IsOf"); case EdmExpressionKind.Labeled: return("LabeledElement"); case EdmExpressionKind.Cast: case EdmExpressionKind.Collection: case EdmExpressionKind.If: case EdmExpressionKind.Null: case EdmExpressionKind.Record: return(expression.ExpressionKind.ToString()); default: return(null); } } if (annotatedElement is IEdmOperationParameter) { return("Parameter"); } else if (annotatedElement is IEdmOperationReturn) { return("ReturnType"); } else if (annotatedElement is IEdmReference) { return("Reference"); } else if (annotatedElement is IEdmInclude) { return("Include"); } else if (annotatedElement is IEdmReferentialConstraint) { return("ReferentialConstraint"); } else if (annotatedElement is IEdmEnumMember) { return("Member"); } else if (annotatedElement is IEdmVocabularyAnnotation) { return("Annotation"); } else if (annotatedElement is IEdmPropertyConstructor) { return("PropertyValue"); } // It's not supported "Schema, UrlRef, OnDelete" return(null); }
public EdmApplyExpression(IEdmFunction appliedFunction, IEdmExpression[] arguments) : this(appliedFunction, (IEnumerable<IEdmExpression>)arguments) { }
public EdmFunctionImport(IEdmEntityContainer container, string name, IEdmTypeReference returnType, IEdmExpression entitySet) : this(container, name, returnType, entitySet, true, false, false) { }
/// <summary> /// Initializes a new instance of the <see cref="EdmValueAnnotation"/> class. /// </summary> /// <param name="target">Element the annotation applies to.</param> /// <param name="term">Term bound by the annotation.</param> /// <param name="value">Expression producing the value of the annotation.</param> public EdmValueAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, IEdmExpression value) : this(target, term, null, value) { }
private bool CompareIEdmExpression(IEdmExpression expected, IEdmExpression actual) { if (expected.ExpressionKind != actual.ExpressionKind) { return(false); } switch (expected.ExpressionKind) { case EdmExpressionKind.Null: return(expected.ExpressionKind == actual.ExpressionKind); case EdmExpressionKind.IntegerConstant: return(((IEdmIntegerConstantExpression)expected).Value == ((IEdmIntegerConstantExpression)actual).Value); case EdmExpressionKind.StringConstant: return(((IEdmStringConstantExpression)expected).Value == ((IEdmStringConstantExpression)actual).Value); case EdmExpressionKind.Record: var expectedRecordExpression = expected as IEdmRecordExpression; var actualRecordExpression = actual as IEdmRecordExpression; if (expectedRecordExpression == null || actualRecordExpression == null) { return(false); } if (expectedRecordExpression.Properties.Count() != actualRecordExpression.Properties.Count()) { return(false); } foreach (var property in expectedRecordExpression.Properties) { if (!actualRecordExpression.Properties.Distinct().Any(n => this.CompareIEdmExpression(property.Value, n.Value))) { return(false); } } return(true); case EdmExpressionKind.Collection: var expectedCollectionExpression = expected as IEdmCollectionExpression; var actualCollectionExpression = actual as IEdmCollectionExpression; if (expectedCollectionExpression == null || actualCollectionExpression == null) { return(false); } if (expectedCollectionExpression.Elements.Count() != actualCollectionExpression.Elements.Count()) { return(false); } var elementCount = expectedCollectionExpression.Elements.Count(); for (int i = 0; i < elementCount; i++) { if (!this.CompareIEdmExpression(expectedCollectionExpression.Elements.ElementAt(i), actualCollectionExpression.Elements.ElementAt(i))) { return(false); } } return(true); default: throw new NotImplementedException(); } }
private static void AddProcedures(this EdmModel model, IEnumerable <ProcedureConfiguration> configurations, EdmEntityContainer container, Dictionary <Type, IEdmType> edmTypeMap, IDictionary <string, EdmNavigationSource> edmNavigationSourceMap) { Contract.Assert(model != null, "Model can't be null"); ValidateActionOverload(configurations.OfType <ActionConfiguration>()); foreach (ProcedureConfiguration procedure in configurations) { IEdmTypeReference returnReference = GetEdmTypeReference( edmTypeMap, procedure.ReturnType, procedure.ReturnType != null && EdmLibHelpers.IsNullable(procedure.ReturnType.ClrType)); IEdmExpression expression = GetEdmEntitySetExpression(edmNavigationSourceMap, procedure); IEdmPathExpression pathExpression = procedure.EntitySetPath != null ? new EdmPathExpression(procedure.EntitySetPath) : null; EdmOperationImport operationImport; switch (procedure.Kind) { case ProcedureKind.Action: operationImport = CreateActionImport(procedure, container, returnReference, expression, pathExpression); break; case ProcedureKind.Function: operationImport = CreateFunctionImport((FunctionConfiguration)procedure, container, returnReference, expression, pathExpression); break; case ProcedureKind.ServiceOperation: Contract.Assert(false, "ServiceOperations are not supported."); goto default; default: Contract.Assert(false, "Unsupported ProcedureKind"); return; } EdmOperation operation = (EdmOperation)operationImport.Operation; if (procedure.IsBindable && procedure.Title != null & procedure.Title != procedure.Name) { model.SetOperationTitleAnnotation(operation, new OperationTitleAnnotation(procedure.Title)); } if (procedure.IsBindable && procedure.NavigationSource != null && edmNavigationSourceMap.ContainsKey(procedure.NavigationSource.Name)) { model.SetAnnotationValue(operation, new ReturnedEntitySetAnnotation(procedure.NavigationSource.Name)); } AddProcedureParameters(operation, procedure, edmTypeMap); if (procedure.IsBindable) { AddProcedureLinkBuilder(model, operation, procedure); ValidateProcedureEntitySetPath(model, operationImport, procedure); } else { container.AddElement(operationImport); } model.AddElement(operation); } }
/// <summary> /// Initializes a new instance of the <see cref="EdmIfExpression"/> class. /// </summary> /// <param name="testExpression">Test expression</param> /// <param name="trueExpression">Expression to evaluate if <paramref name="testExpression"/> evaluates to true.</param> /// <param name="falseExpression">Expression to evaluate if <paramref name="testExpression"/> evaluates to false.</param> public EdmIfExpression(IEdmExpression testExpression, IEdmExpression trueExpression, IEdmExpression falseExpression) { EdmUtil.CheckArgumentNull(testExpression, "testExpression"); EdmUtil.CheckArgumentNull(trueExpression, "trueExpression"); EdmUtil.CheckArgumentNull(falseExpression, "falseExpression"); this.testExpression = testExpression; this.trueExpression = trueExpression; this.falseExpression = falseExpression; }
public EdmValueTermReferenceExpression(IEdmExpression baseExpression, IEdmValueTerm term) : this(baseExpression, term, null) { }
/// <summary> /// Initializes a new instance of the <see cref="EdmValueTermReferenceExpression"/> class. /// </summary> /// <param name="baseExpression">Expression for the structured value containing the referenced term property.</param> /// <param name="term">Referenced value term.</param> public EdmValueTermReferenceExpression(IEdmExpression baseExpression, IEdmValueTerm term) : this(baseExpression, term, null) { }
public void AddProperty(string propertyName, IEdmExpression expression) { properties.Add(new StubPropertyConstructor(propertyName, expression)); }
/// <summary> /// Determines whether or not the value is 'KeyAsSegment'. /// </summary> /// <param name="value">The value to check.</param> /// <returns>True if the value is 'KeyAsSegment'.; false otherwise.</returns> private static bool IsKeyAsSegment(IEdmExpression value) { return(value != null && value.ExpressionKind == EdmExpressionKind.StringConstant && ((IEdmStringConstantExpression)value).Value == KeyAsSegmentConventionName); }
/// <summary> /// Adds the function and function import. /// </summary> /// <param name="container">The container.</param> /// <param name="model">The model.</param> /// <param name="name">The name.</param> /// <param name="returnType">Type of the return.</param> /// <param name="entitySet">The entity set.</param> /// <param name="isComposable">if set to <c>true</c> [is composable].</param> /// <param name="isBound">if set to <c>true</c> [is bound].</param> /// <returns></returns> public static EdmFunctionImport AddFunctionAndFunctionImport(this EdmEntityContainer container, EdmModel model, string name, IEdmTypeReference returnType, IEdmExpression entitySet = null, bool isComposable = false, bool isBound = false) { EdmFunction function = new EdmFunction(container.Namespace, name, returnType, isBound, null, isComposable); model.AddElement(function); return container.AddFunctionImport(name, function, entitySet); }
private IEdmModel BuildValueAnnotationModelWithEdmValueKind(IEdmTypeReference valueKindType, IEdmExpression valueAnnotationValue) { var model = this.BuildBasicModelWithValueTerm(valueKindType); var valueAnnotation = new EdmAnnotation( model.FindEntityContainer("foo.Container"), model.FindValueTerm("foo.ValueTerm"), valueAnnotationValue); model.AddVocabularyAnnotation(valueAnnotation); return(model); }
private IEdmVocabularyAnnotation CreateAndAttachValueAnnotation(IEdmVocabularyAnnotatable target, IEdmValueTerm term, IEdmExpression value) { return this.CreateAndAttachValueAnnotation(target, term, value, null); }
private IEdmModel BuildValueAnnotationModelWithEdmValueKind(IEdmTypeReference valueKindType, IEdmExpression valueAnnotationValue) { var model = this.BuildBasicModelWithValueTerm(valueKindType); var valueAnnotation = new EdmAnnotation( model.FindEntityContainer("foo.Container"), model.FindValueTerm("foo.ValueTerm"), valueAnnotationValue); model.AddVocabularyAnnotation(valueAnnotation); return model; }
private static EdmOperationImport CreateActionImport( ProcedureConfiguration procedure, EdmEntityContainer container, IEdmTypeReference returnReference, IEdmExpression expression, IEdmPathExpression pathExpression) { EdmAction operation = new EdmAction( container.Namespace, procedure.Name, returnReference, procedure.IsBindable, pathExpression); return new EdmActionImport(container, procedure.Name, operation, expression); }
public virtual EdmFunctionImport AddFunctionImport(string name, IEdmTypeReference returnType, IEdmExpression entitySet) { EdmFunctionImport edmFunctionImport = new EdmFunctionImport(this, name, returnType, entitySet); this.AddElement(edmFunctionImport); return edmFunctionImport; }
/// <summary> /// Initializes a new instance of the <see cref="EdmVocabularyAnnotation"/> class. /// </summary> /// <param name="target">Element the annotation applies to.</param> /// <param name="term">Term bound by the annotation.</param> /// <param name="value">Expression producing the value of the annotation.</param> public EdmVocabularyAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, IEdmExpression value) : this(target, term, null, value) { }
/// <summary> /// Evaluates an expression in the context of a value and a target type. /// </summary> /// <typeparam name="T">The CLR type of the value to be returned.</typeparam> /// <param name="expression">Expression to evaluate.</param> /// <param name="context">Value to use as context in evaluating the expression.</param> /// <param name="targetType">Type to which the result value is expected to conform.</param> /// <returns>The value that results from evaluating the expression in the context of the supplied value, asserted to be of the targetType.</returns> public T EvaluateToClrValue <T>(IEdmExpression expression, IEdmStructuredValue context, IEdmTypeReference targetType) { IEdmValue edmValue = this.Evaluate(expression, context, targetType); return(this.edmToClrConverter.AsClrValue <T>(edmValue)); }
/// <summary> /// Initializes a new instance of the <see cref="EdmVocabularyAnnotation"/> class. /// </summary> /// <param name="target">Element the annotation applies to.</param> /// <param name="term">Term bound by the annotation.</param> /// <param name="qualifier">Qualifier used to discriminate between multiple bindings of the same property or type.</param> /// <param name="value">Expression producing the value of the annotation.</param> public EdmVocabularyAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, string qualifier, IEdmExpression value) { EdmUtil.CheckArgumentNull(target, "target"); EdmUtil.CheckArgumentNull(term, "term"); EdmUtil.CheckArgumentNull(value, "value"); this.target = target; this.term = term; this.qualifier = qualifier; this.value = value; UseDefault = false; }
/// <summary> /// Initializes a new instance of the <see cref="EdmValueAnnotation"/> class. /// </summary> /// <param name="target">Element the annotation applies to.</param> /// <param name="term">Term bound by the annotation.</param> /// <param name="qualifier">Qualifier used to discriminate between multiple bindings of the same property or type.</param> /// <param name="value">Expression producing the value of the annotation.</param> public EdmValueAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, string qualifier, IEdmExpression value) : base(target, term, qualifier) { EdmUtil.CheckArgumentNull(value, "value"); this.value = value; }