示例#1
0
 /// <summary>
 /// Gets the value for the EDMX version of the <paramref name="model"/>.
 /// </summary>
 /// <param name="model">Model the version has been set for.</param>
 /// <returns>The version.</returns>
 public static Version GetEdmxVersion(this IEdmModel model)
 {
     EdmUtil.CheckArgumentNull(model, "model");
     return(model.GetAnnotationValue <Version>(model, EdmConstants.InternalUri, CsdlConstants.EdmxVersionAnnotation));
 }
示例#2
0
        /// <summary>
        /// Converts <paramref name="edmValue"/> to a <see cref="Microsoft.OData.Edm.TimeOfDay"/> value.
        /// </summary>
        /// <param name="edmValue">The EDM value to be converted.</param>
        /// <returns>Converted TimeOfDay.</returns>
        /// <exception cref="InvalidCastException">Exception is thrown if <paramref name="edmValue"/> is not <see cref="IEdmTimeOfDayValue"/>.</exception>
        internal static TimeOfDay AsClrTimeOfDay(IEdmValue edmValue)
        {
            EdmUtil.CheckArgumentNull(edmValue, "edmValue");

            return(((IEdmTimeOfDayValue)edmValue).Value);
        }
示例#3
0
        /// <summary>
        /// Converts <paramref name="edmValue"/> to a <see cref="System.Decimal"/> value.
        /// </summary>
        /// <param name="edmValue">The EDM value to be converted.</param>
        /// <returns>Converted decimal.</returns>
        /// <exception cref="InvalidCastException">Exception is thrown if <paramref name="edmValue"/> is not <see cref="IEdmDecimalValue"/>.</exception>
        internal static decimal AsClrDecimal(IEdmValue edmValue)
        {
            EdmUtil.CheckArgumentNull(edmValue, "edmValue");

            return(((IEdmDecimalValue)edmValue).Value);
        }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmBinaryConstant"/> class.
 /// </summary>
 /// <param name="type">Type of the integer.</param>
 /// <param name="value">Integer value represented by this value.</param>
 public EdmBinaryConstant(IEdmBinaryTypeReference type, byte[] value)
     : base(type)
 {
     EdmUtil.CheckArgumentNull(value, "value");
     this.value = value;
 }
示例#5
0
        /// <summary>
        /// Converts <paramref name="edmValue"/> to a <see cref="System.Int64"/> value.
        /// </summary>
        /// <param name="edmValue">The EDM value to be converted.</param>
        /// <returns>Converted integer.</returns>
        /// <exception cref="InvalidCastException">Exception is thrown if <paramref name="edmValue"/> is not <see cref="IEdmIntegerValue"/>.</exception>
        internal static Int64 AsClrInt64(IEdmValue edmValue)
        {
            EdmUtil.CheckArgumentNull(edmValue, "edmValue");

            return(((IEdmIntegerValue)edmValue).Value);
        }
 /// <summary>
 /// Initializes a new instance of the ValidationRuleSet class.
 /// </summary>
 /// <param name="baseSet">Ruleset whose rules should be contained in this set.</param>
 /// <param name="newRules">Additional rules to add to the set.</param>
 public ValidationRuleSet(IEnumerable <ValidationRule> baseSet, IEnumerable <ValidationRule> newRules)
     : this(EdmUtil.CheckArgumentNull(baseSet, "baseSet").Concat(EdmUtil.CheckArgumentNull(newRules, "newRules")))
 {
 }
 /// <summary>
 /// Initializes a new instance of <see cref="EdmReferentialConstraint"/>.
 /// </summary>
 /// <param name="propertyPairs">The set of property pairs from the referential constraint.</param>
 public EdmReferentialConstraint(IEnumerable <EdmReferentialConstraintPropertyPair> propertyPairs)
 {
     EdmUtil.CheckArgumentNull(propertyPairs, "propertyPairs");
     this.propertyPairs = propertyPairs.ToList();
 }
示例#8
0
        private IEdmValue Eval(IEdmExpression expression, IEdmStructuredValue context)
        {
            Func <IEdmValue[], IEdmValue> func = null;
            IEdmStructuredTypeReference   edmStructuredTypeReference;
            IEdmCollectionTypeReference   edmCollectionTypeReference;
            object            traceString;
            EdmExpressionKind expressionKind = expression.ExpressionKind;

            switch (expressionKind)
            {
            case EdmExpressionKind.BinaryConstant:
            {
                return((IEdmBinaryConstantExpression)expression);
            }

            case EdmExpressionKind.BooleanConstant:
            {
                return((IEdmBooleanConstantExpression)expression);
            }

            case EdmExpressionKind.DateTimeConstant:
            {
                return((IEdmDateTimeConstantExpression)expression);
            }

            case EdmExpressionKind.DateTimeOffsetConstant:
            {
                return((IEdmDateTimeOffsetConstantExpression)expression);
            }

            case EdmExpressionKind.DecimalConstant:
            {
                return((IEdmDecimalConstantExpression)expression);
            }

            case EdmExpressionKind.FloatingConstant:
            {
                return((IEdmFloatingConstantExpression)expression);
            }

            case EdmExpressionKind.GuidConstant:
            {
                return((IEdmGuidConstantExpression)expression);
            }

            case EdmExpressionKind.IntegerConstant:
            {
                return((IEdmIntegerConstantExpression)expression);
            }

            case EdmExpressionKind.StringConstant:
            {
                return((IEdmStringConstantExpression)expression);
            }

            case EdmExpressionKind.TimeConstant:
            {
                return((IEdmTimeConstantExpression)expression);
            }

            case EdmExpressionKind.Null:
            {
                return((IEdmNullExpression)expression);
            }

            case EdmExpressionKind.Record:
            {
                IEdmRecordExpression edmRecordExpression = (IEdmRecordExpression)expression;
                EdmExpressionEvaluator.DelayedExpressionContext delayedExpressionContext = new EdmExpressionEvaluator.DelayedExpressionContext(this, context);
                List <IEdmPropertyValue> edmPropertyValues = new List <IEdmPropertyValue>();
                foreach (IEdmPropertyConstructor property in edmRecordExpression.Properties)
                {
                    edmPropertyValues.Add(new EdmExpressionEvaluator.DelayedRecordProperty(delayedExpressionContext, property));
                }
                if (edmRecordExpression.DeclaredType != null)
                {
                    edmStructuredTypeReference = edmRecordExpression.DeclaredType.AsStructured();
                }
                else
                {
                    edmStructuredTypeReference = null;
                }
                EdmStructuredValue edmStructuredValue = new EdmStructuredValue(edmStructuredTypeReference, edmPropertyValues);
                return(edmStructuredValue);
            }

            case EdmExpressionKind.Collection:
            {
                IEdmCollectionExpression edmCollectionExpression = (IEdmCollectionExpression)expression;
                EdmExpressionEvaluator.DelayedExpressionContext delayedExpressionContext1 = new EdmExpressionEvaluator.DelayedExpressionContext(this, context);
                List <IEdmDelayedValue> edmDelayedValues = new List <IEdmDelayedValue>();
                foreach (IEdmExpression element in edmCollectionExpression.Elements)
                {
                    edmDelayedValues.Add(this.MapLabeledExpressionToDelayedValue(element, delayedExpressionContext1, context));
                }
                if (edmCollectionExpression.DeclaredType != null)
                {
                    edmCollectionTypeReference = edmCollectionExpression.DeclaredType.AsCollection();
                }
                else
                {
                    edmCollectionTypeReference = null;
                }
                EdmCollectionValue edmCollectionValue = new EdmCollectionValue(edmCollectionTypeReference, edmDelayedValues);
                return(edmCollectionValue);
            }

            case EdmExpressionKind.Path:
            {
                EdmUtil.CheckArgumentNull <IEdmStructuredValue>(context, "context");
                IEdmPathExpression edmPathExpression = (IEdmPathExpression)expression;
                IEdmValue          edmValue          = context;
                foreach (string path in edmPathExpression.Path)
                {
                    edmValue = this.FindProperty(path, edmValue);
                    if (edmValue != null)
                    {
                        continue;
                    }
                    throw new InvalidOperationException(Strings.Edm_Evaluator_UnboundPath(path));
                }
                return(edmValue);
            }

            case EdmExpressionKind.ParameterReference:
            case EdmExpressionKind.FunctionReference:
            case EdmExpressionKind.PropertyReference:
            case EdmExpressionKind.ValueTermReference:
            case EdmExpressionKind.EntitySetReference:
            case EdmExpressionKind.EnumMemberReference:
            {
                throw new InvalidOperationException(string.Concat("Not yet implemented: evaluation of ", expression.ExpressionKind.ToString(), " expressions."));
            }

            case EdmExpressionKind.If:
            {
                IEdmIfExpression edmIfExpression = (IEdmIfExpression)expression;
                if (!((IEdmBooleanValue)this.Eval(edmIfExpression.TestExpression, context)).Value)
                {
                    return(this.Eval(edmIfExpression.FalseExpression, context));
                }
                else
                {
                    return(this.Eval(edmIfExpression.TrueExpression, context));
                }
            }

            case EdmExpressionKind.AssertType:
            {
                IEdmAssertTypeExpression edmAssertTypeExpression = (IEdmAssertTypeExpression)expression;
                IEdmValue         edmValue1 = this.Eval(edmAssertTypeExpression.Operand, context);
                IEdmTypeReference type      = edmAssertTypeExpression.Type;
                return(EdmExpressionEvaluator.AssertType(type, edmValue1));
            }

            case EdmExpressionKind.IsType:
            {
                IEdmIsTypeExpression edmIsTypeExpression = (IEdmIsTypeExpression)expression;
                IEdmValue            edmValue2           = this.Eval(edmIsTypeExpression.Operand, context);
                IEdmTypeReference    edmTypeReference    = edmIsTypeExpression.Type;
                return(new EdmBooleanConstant(EdmExpressionEvaluator.MatchesType(edmTypeReference, edmValue2)));
            }

            case EdmExpressionKind.FunctionApplication:
            {
                IEdmApplyExpression             edmApplyExpression             = (IEdmApplyExpression)expression;
                IEdmExpression                  appliedFunction                = edmApplyExpression.AppliedFunction;
                IEdmFunctionReferenceExpression edmFunctionReferenceExpression = appliedFunction as IEdmFunctionReferenceExpression;
                if (edmFunctionReferenceExpression != null)
                {
                    IList <IEdmExpression> list          = edmApplyExpression.Arguments.ToList <IEdmExpression>();
                    IEdmValue[]            edmValueArray = new IEdmValue[list.Count <IEdmExpression>()];
                    int num = 0;
                    foreach (IEdmExpression edmExpression in list)
                    {
                        int num1 = num;
                        num = num1 + 1;
                        edmValueArray[num1] = this.Eval(edmExpression, context);
                    }
                    IEdmFunction referencedFunction = edmFunctionReferenceExpression.ReferencedFunction;
                    if (referencedFunction.IsBad() || !this.builtInFunctions.TryGetValue(referencedFunction, out func))
                    {
                        if (this.lastChanceFunctionApplier != null)
                        {
                            return(this.lastChanceFunctionApplier(referencedFunction.FullName(), edmValueArray));
                        }
                    }
                    else
                    {
                        return(func(edmValueArray));
                    }
                }
                if (edmFunctionReferenceExpression != null)
                {
                    traceString = edmFunctionReferenceExpression.ReferencedFunction.ToTraceString();
                }
                else
                {
                    traceString = string.Empty;
                }
                throw new InvalidOperationException(Strings.Edm_Evaluator_UnboundFunction(traceString));
            }

            case EdmExpressionKind.LabeledExpressionReference:
            {
                return(this.MapLabeledExpressionToDelayedValue(((IEdmLabeledExpressionReferenceExpression)expression).ReferencedLabeledExpression, null, context).Value);
            }

            case EdmExpressionKind.Labeled:
            {
                return(this.MapLabeledExpressionToDelayedValue(expression, new EdmExpressionEvaluator.DelayedExpressionContext(this, context), context).Value);
            }
            }
            int expressionKind1 = (int)expression.ExpressionKind;

            throw new InvalidOperationException(Strings.Edm_Evaluator_UnrecognizedExpressionKind(expressionKind1.ToString(CultureInfo.InvariantCulture)));
        }
示例#9
0
 public IEdmValue Evaluate(IEdmExpression expression)
 {
     EdmUtil.CheckArgumentNull <IEdmExpression>(expression, "expression");
     return(this.Eval(expression, null));
 }
示例#10
0
 /// <summary>
 /// Adds a schema element to this model.
 /// </summary>
 /// <param name="element">The element to register.</param>
 protected void RegisterElement(IEdmSchemaElement element)
 {
     EdmUtil.CheckArgumentNull(element, "element");
     RegistrationHelper.RegisterSchemaElement(element, this.schemaTypeDictionary, this.valueTermDictionary, this.functionDictionary, this.containersDictionary);
 }
示例#11
0
 /// <summary>
 /// Adds a model reference to this model.
 /// </summary>
 /// <param name="model">The model to reference.</param>
 protected void AddReferencedModel(IEdmModel model)
 {
     EdmUtil.CheckArgumentNull(model, "model");
     this.referencedEdmModels.Add(model);
 }
示例#12
0
 /// <summary>
 /// Gets the preferred prefix mappings for xml namespaces from an IEdmModel
 /// </summary>
 /// <param name="model">Reference to the calling object.</param>
 /// <returns>Namespace prefixes that exist on the model.</returns>
 public static IEnumerable <KeyValuePair <string, string> > GetNamespacePrefixMappings(this IEdmModel model)
 {
     EdmUtil.CheckArgumentNull(model, "model");
     return(model.GetAnnotationValue <IEnumerable <KeyValuePair <string, string> > >(model, EdmConstants.InternalUri, CsdlConstants.NamespacePrefixAnnotation));
 }
示例#13
0
 /// <summary>
 /// Sets an annotation on the IEdmModel to notify the serializer of preferred prefix mappings for xml namespaces.
 /// </summary>
 /// <param name="model">Reference to the calling object.</param>
 /// <param name="mappings">XmlNamespaceManage containing mappings between namespace prefixes and xml namespaces.</param>
 public static void SetNamespacePrefixMappings(this IEdmModel model, IEnumerable <KeyValuePair <string, string> > mappings)
 {
     EdmUtil.CheckArgumentNull(model, "model");
     model.SetAnnotationValue(model, EdmConstants.InternalUri, CsdlConstants.NamespacePrefixAnnotation, mappings);
 }
示例#14
0
 /// <summary>
 /// Sets a value of EDMX version attribute of the <paramref name="model"/>.
 /// </summary>
 /// <param name="model">The model the version should be set for.</param>
 /// <param name="version">The version.</param>
 public static void SetEdmxVersion(this IEdmModel model, Version version)
 {
     EdmUtil.CheckArgumentNull(model, "model");
     model.SetAnnotationValue(model, EdmConstants.InternalUri, CsdlConstants.EdmxVersionAnnotation, version);
 }
示例#15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmEntitySetReferenceExpression"/> class.
 /// </summary>
 /// <param name="referencedEntitySet">Referenced entity set.</param>
 public EdmEntitySetReferenceExpression(IEdmEntitySet referencedEntitySet)
 {
     EdmUtil.CheckArgumentNull(referencedEntitySet, "referencedEntitySet");
     this.referencedEntitySet = referencedEntitySet;
 }
示例#16
0
 public IEdmValue Evaluate(IEdmExpression expression, IEdmStructuredValue context)
 {
     EdmUtil.CheckArgumentNull <IEdmExpression>(expression, "expression");
     return(this.Eval(expression, context));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmOperationReferenceExpression"/> class.
 /// </summary>
 /// <param name="referencedOperation">Referenced operation</param>
 public EdmOperationReferenceExpression(IEdmOperation referencedOperation)
 {
     EdmUtil.CheckArgumentNull(referencedOperation, "referencedFunction");
     this.referencedOperation = referencedOperation;
 }
示例#18
0
 public IEdmValue Evaluate(IEdmExpression expression, IEdmStructuredValue context, IEdmTypeReference targetType)
 {
     EdmUtil.CheckArgumentNull <IEdmExpression>(expression, "expression");
     EdmUtil.CheckArgumentNull <IEdmTypeReference>(targetType, "targetType");
     return(EdmExpressionEvaluator.AssertType(targetType, this.Eval(expression, context)));
 }
示例#19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmTypeAnnotation"/> 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="propertyValueBindings">Value annotations for the properties of the type.</param>
 public EdmTypeAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, string qualifier, IEnumerable <IEdmPropertyValueBinding> propertyValueBindings)
     : base(target, term, qualifier)
 {
     EdmUtil.CheckArgumentNull(propertyValueBindings, "propertyValueBindings");
     this.propertyValueBindings = propertyValueBindings;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmEnumMemberReferenceExpression"/> class.
 /// </summary>
 /// <param name="referencedEnumMember">Referenced enum member.</param>
 public EdmEnumMemberReferenceExpression(IEdmEnumMember referencedEnumMember)
 {
     EdmUtil.CheckArgumentNull(referencedEnumMember, "referencedEnumMember");
     this.referencedEnumMember = referencedEnumMember;
 }
示例#21
0
 public void AddParameter(IEdmFunctionParameter parameter)
 {
     EdmUtil.CheckArgumentNull <IEdmFunctionParameter>(parameter, "parameter");
     this.parameters.Add(parameter);
 }
示例#22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmCollectionType"/> class.
 /// </summary>
 /// <param name="elementType">The type of the elements in this collection.</param>
 public EdmCollectionType(IEdmTypeReference elementType)
 {
     EdmUtil.CheckArgumentNull(elementType, "elementType");
     this.elementType = elementType;
 }
示例#23
0
        /// <summary>
        /// Converts <paramref name="edmValue"/> to a <see cref="System.Boolean"/> value.
        /// </summary>
        /// <param name="edmValue">The EDM value to be converted.</param>
        /// <returns>Converted boolean.</returns>
        /// <exception cref="InvalidCastException">Exception is thrown if <paramref name="edmValue"/> is not <see cref="IEdmBooleanValue"/>.</exception>
        internal static Boolean AsClrBoolean(IEdmValue edmValue)
        {
            EdmUtil.CheckArgumentNull(edmValue, "edmValue");

            return(((IEdmBooleanValue)edmValue).Value);
        }
示例#24
0
 public EdmEntityReferenceType(IEdmEntityType entityType)
 {
     EdmUtil.CheckArgumentNull <IEdmEntityType>(entityType, "entityType");
     this.entityType = entityType;
 }
示例#25
0
        /// <summary>
        /// Converts <paramref name="edmValue"/> to a <see cref="System.Double"/> value.
        /// </summary>
        /// <param name="edmValue">The EDM value to be converted.</param>
        /// <returns>Converted double.</returns>
        /// <exception cref="InvalidCastException">Exception is thrown if <paramref name="edmValue"/> is not <see cref="IEdmFloatingValue"/>.</exception>
        internal static Double AsClrDouble(IEdmValue edmValue)
        {
            EdmUtil.CheckArgumentNull(edmValue, "edmValue");

            return(((IEdmFloatingValue)edmValue).Value);
        }
示例#26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmPathExpression"/> class.
 /// </summary>
 /// <param name="path">Path string containing segments seperated by '/'. For example: "A.B/C/D.E/Func1(NS.T,NS.T2)/P1".</param>
 public EdmPathExpression(string path)
     : this(EdmUtil.CheckArgumentNull(path, "path").Split('/'))
 {
 }
示例#27
0
        /// <summary>
        /// Converts <paramref name="edmValue"/> to a <see cref="Microsoft.OData.Edm.Date"/> value.
        /// </summary>
        /// <param name="edmValue">The EDM value to be converted.</param>
        /// <returns>Converted date.</returns>
        /// <exception cref="InvalidCastException">Exception is thrown if <paramref name="edmValue"/> is not <see cref="IEdmDateValue"/>.</exception>
        internal static Date AsClrDate(IEdmValue edmValue)
        {
            EdmUtil.CheckArgumentNull(edmValue, "edmValue");

            return(((IEdmDateValue)edmValue).Value);
        }
        /// <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.FunctionApplication:
                IEdmApplyExpression applyExpression = (IEdmApplyExpression)expression;
                if (applyExpression.AppliedFunction != null)
                {
                    IEdmOperation operation = applyExpression.AppliedFunction 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);
            }
        }
示例#29
0
        /// <summary>
        /// Converts <paramref name="edmValue"/> to a <see cref="System.TimeSpan"/> value.
        /// </summary>
        /// <param name="edmValue">The EDM value to be converted.</param>
        /// <returns>Converted Duration.</returns>
        /// <exception cref="InvalidCastException">Exception is thrown if <paramref name="edmValue"/> is not <see cref="IEdmDurationValue"/>.</exception>
        internal static TimeSpan AsClrDuration(IEdmValue edmValue)
        {
            EdmUtil.CheckArgumentNull(edmValue, "edmValue");

            return(((IEdmDurationValue)edmValue).Value);
        }
示例#30
0
 /// <summary>
 /// Gets the namespaces in all schemas having alias, excluding those without alias.
 /// </summary>
 /// <param name="model">The IEdmModel.</param>
 /// <returns>The namespaces in all schemas having alias.</returns>
 internal static VersioningList <string> GetUsedNamespacesHavingAlias(this IEdmModel model)
 {
     EdmUtil.CheckArgumentNull(model, "model");
     return(model.GetAnnotationValue <VersioningList <string> >(model, EdmConstants.InternalUri, CsdlConstants.UsedNamespacesAnnotation));
 }