コード例 #1
0
        private IEdmExpression ComputeAppliedFunction()
        {
            if (this.expression.Function == null)
            {
                return(CsdlSemanticsModel.WrapExpression(this.expression.Arguments.FirstOrDefault(null), this.bindingContext, this.schema));
            }
            else
            {
                IEdmFunction referenced;
                IEnumerable <IEdmFunction> candidateFunctions = this.schema.FindFunctions(this.expression.Function);
                if (candidateFunctions.Count() == 0)
                {
                    referenced = new UnresolvedFunction(this.expression.Function, Edm.Strings.Bad_UnresolvedFunction(this.expression.Function), this.Location);
                }
                else
                {
                    candidateFunctions = candidateFunctions.Where(this.IsMatchingFunction);
                    if (candidateFunctions.Count() > 1)
                    {
                        referenced = new UnresolvedFunction(this.expression.Function, Edm.Strings.Bad_AmbiguousFunction(this.expression.Function), this.Location);
                    }
                    else if (candidateFunctions.Count() == 0)
                    {
                        referenced = new UnresolvedFunction(this.expression.Function, Edm.Strings.Bad_FunctionParametersDontMatch(this.expression.Function), this.Location);
                    }
                    else
                    {
                        referenced = candidateFunctions.Single();
                    }
                }

                return(new Library.Expressions.EdmFunctionReferenceExpression(referenced));
            }
        }
コード例 #2
0
        private IEdmExpression ComputeAppliedFunction()
        {
            IEdmFunction unresolvedFunction;

            if (this.expression.Function != null)
            {
                IEnumerable <IEdmFunction> edmFunctions = this.schema.FindFunctions(this.expression.Function);
                if (edmFunctions.Count <IEdmFunction>() != 0)
                {
                    edmFunctions = edmFunctions.Where <IEdmFunction>(new Func <IEdmFunction, bool>(this.IsMatchingFunction));
                    if (edmFunctions.Count <IEdmFunction>() <= 1)
                    {
                        if (edmFunctions.Count <IEdmFunction>() != 0)
                        {
                            unresolvedFunction = edmFunctions.Single <IEdmFunction>();
                        }
                        else
                        {
                            unresolvedFunction = new UnresolvedFunction(this.expression.Function, Strings.Bad_FunctionParametersDontMatch(this.expression.Function), base.Location);
                        }
                    }
                    else
                    {
                        unresolvedFunction = new UnresolvedFunction(this.expression.Function, Strings.Bad_AmbiguousFunction(this.expression.Function), base.Location);
                    }
                }
                else
                {
                    unresolvedFunction = new UnresolvedFunction(this.expression.Function, Strings.Bad_UnresolvedFunction(this.expression.Function), base.Location);
                }
                return(new EdmFunctionReferenceExpression(unresolvedFunction));
            }
            else
            {
                return(CsdlSemanticsModel.WrapExpression(this.expression.Arguments.FirstOrDefault <CsdlExpressionBase>(null), this.bindingContext, this.schema));
            }
        }
コード例 #3
0
		private IEdmExpression ComputeAppliedFunction()
		{
			IEdmFunction unresolvedFunction;
			if (this.expression.Function != null)
			{
				IEnumerable<IEdmFunction> edmFunctions = this.schema.FindFunctions(this.expression.Function);
				if (edmFunctions.Count<IEdmFunction>() != 0)
				{
					edmFunctions = edmFunctions.Where<IEdmFunction>(new Func<IEdmFunction, bool>(this.IsMatchingFunction));
					if (edmFunctions.Count<IEdmFunction>() <= 1)
					{
						if (edmFunctions.Count<IEdmFunction>() != 0)
						{
							unresolvedFunction = edmFunctions.Single<IEdmFunction>();
						}
						else
						{
							unresolvedFunction = new UnresolvedFunction(this.expression.Function, Strings.Bad_FunctionParametersDontMatch(this.expression.Function), base.Location);
						}
					}
					else
					{
						unresolvedFunction = new UnresolvedFunction(this.expression.Function, Strings.Bad_AmbiguousFunction(this.expression.Function), base.Location);
					}
				}
				else
				{
					unresolvedFunction = new UnresolvedFunction(this.expression.Function, Strings.Bad_UnresolvedFunction(this.expression.Function), base.Location);
				}
				return new EdmFunctionReferenceExpression(unresolvedFunction);
			}
			else
			{
				return CsdlSemanticsModel.WrapExpression(this.expression.Arguments.FirstOrDefault<CsdlExpressionBase>(null), this.bindingContext, this.schema);
			}
		}
コード例 #4
0
        private IEdmVocabularyAnnotatable ComputeTarget()
        {
            if (this.targetContext != null)
            {
                return(this.targetContext);
            }
            else
            {
                Debug.Assert(this.annotationsContext != null, "Annotation must either have a target context or annotations context");
                string              target              = this.annotationsContext.Annotations.Target;
                string[]            targetSegments      = target.Split('/');
                int                 targetSegmentsCount = targetSegments.Count();
                IEdmEntityContainer container;

                if (targetSegmentsCount == 1)
                {
                    string         elementName = targetSegments[0];
                    IEdmSchemaType type        = this.schema.FindType(elementName);
                    if (type != null)
                    {
                        return(type);
                    }

                    IEdmValueTerm term = this.schema.FindValueTerm(elementName);
                    if (term != null)
                    {
                        return(term);
                    }

                    IEdmFunction function = this.FindParameterizedFunction(elementName, this.Schema.FindFunctions, this.CreateAmbiguousFunction);
                    if (function != null)
                    {
                        return(function);
                    }

                    container = this.schema.FindEntityContainer(elementName);
                    if (container != null)
                    {
                        return(container);
                    }

                    return(new UnresolvedType(this.Schema.UnresolvedName(targetSegments[0]), this.Location));
                }

                if (targetSegmentsCount == 2)
                {
                    container = this.schema.FindEntityContainer(targetSegments[0]);
                    if (container != null)
                    {
                        IEdmEntityContainerElement containerElement = container.FindEntitySet(targetSegments[1]);
                        if (containerElement != null)
                        {
                            return(containerElement);
                        }

                        IEdmFunctionImport functionImport = this.FindParameterizedFunction(targetSegments[1], container.FindFunctionImports, this.CreateAmbiguousFunctionImport);
                        if (functionImport != null)
                        {
                            return(functionImport);
                        }

                        return(new UnresolvedEntitySet(targetSegments[1], container, this.Location));
                    }

                    IEdmStructuredType type = this.schema.FindType(targetSegments[0]) as IEdmStructuredType;
                    if (type != null)
                    {
                        IEdmProperty property = type.FindProperty(targetSegments[1]);
                        if (property != null)
                        {
                            return(property);
                        }

                        return(new UnresolvedProperty(type, targetSegments[1], this.Location));
                    }

                    IEdmFunction function = this.FindParameterizedFunction(targetSegments[0], this.Schema.FindFunctions, this.CreateAmbiguousFunction);
                    if (function != null)
                    {
                        IEdmFunctionParameter parameter = function.FindParameter(targetSegments[1]);
                        if (parameter != null)
                        {
                            return(parameter);
                        }

                        return(new UnresolvedParameter(function, targetSegments[1], this.Location));
                    }

                    return(new UnresolvedProperty(new UnresolvedEntityType(this.Schema.UnresolvedName(targetSegments[0]), this.Location), targetSegments[1], this.Location));
                }

                if (targetSegmentsCount == 3)
                {
                    // The only valid target with three segments is a function parameter.
                    string containerName = targetSegments[0];
                    string functionName  = targetSegments[1];
                    string parameterName = targetSegments[2];

                    container = this.Model.FindEntityContainer(containerName);
                    if (container != null)
                    {
                        IEdmFunctionImport functionImport = this.FindParameterizedFunction(functionName, container.FindFunctionImports, this.CreateAmbiguousFunctionImport);
                        if (functionImport != null)
                        {
                            IEdmFunctionParameter parameter = functionImport.FindParameter(parameterName);
                            if (parameter != null)
                            {
                                return(parameter);
                            }

                            return(new UnresolvedParameter(functionImport, parameterName, this.Location));
                        }
                    }

                    string             qualifiedFunctionName = containerName + "/" + functionName;
                    UnresolvedFunction unresolvedFunction    = new UnresolvedFunction(qualifiedFunctionName, Edm.Strings.Bad_UnresolvedFunction(qualifiedFunctionName), this.Location);
                    return(new UnresolvedParameter(unresolvedFunction, parameterName, this.Location));
                }

                return(new BadElement(new EdmError[] { new EdmError(this.Location, EdmErrorCode.ImpossibleAnnotationsTarget, Edm.Strings.CsdlSemantics_ImpossibleAnnotationsTarget(target)) }));
            }
        }
コード例 #5
0
        private IEdmExpression ComputeAppliedFunction()
        {
            if (this.expression.Function == null)
            {
                return CsdlSemanticsModel.WrapExpression(this.expression.Arguments.FirstOrDefault(null), this.bindingContext, this.schema);
            }
            else
            {
                IEdmFunction referenced;
                IEnumerable<IEdmFunction> candidateFunctions = this.schema.FindFunctions(this.expression.Function);
                if (candidateFunctions.Count() == 0)
                {
                    referenced = new UnresolvedFunction(this.expression.Function, Edm.Strings.Bad_UnresolvedFunction(this.expression.Function), this.Location);
                }
                else
                {
                    candidateFunctions = candidateFunctions.Where(this.IsMatchingFunction);
                    if (candidateFunctions.Count() > 1)
                    {
                        referenced = new UnresolvedFunction(this.expression.Function, Edm.Strings.Bad_AmbiguousFunction(this.expression.Function), this.Location);
                    }
                    else if (candidateFunctions.Count() == 0)
                    {
                        referenced = new UnresolvedFunction(this.expression.Function, Edm.Strings.Bad_FunctionParametersDontMatch(this.expression.Function), this.Location);
                    }
                    else
                    {
                        referenced = candidateFunctions.Single();
                    }
                }

                return new Library.Expressions.EdmFunctionReferenceExpression(referenced);
            }
        }