private QueryModelReference ComputeModelReference()
        {
            QueryModelReference modelReference = null;

            var methodCall = this.VisitedNode as MethodCallExpression;

            if (methodCall != null)
            {
                var method = methodCall.Method;
                if (method.DeclaringType == typeof(ApiData) &&
                    method.Name != MethodNameOfApiDataValue)
                {
                    modelReference = ComputeApiDataReference(methodCall);
                }
                else if (method.GetCustomAttributes <ExtensionAttribute>().Any())
                {
                    var thisModelReference = this.GetModelReferenceForNode(
                        methodCall.Arguments[0]);
                    if (thisModelReference != null)
                    {
                        modelReference = ComputeDerivedDataReference(
                            methodCall, thisModelReference);
                    }
                }
            }

            var parameter = this.VisitedNode as ParameterExpression;

            if (parameter != null)
            {
                foreach (var node in this.GetExpressionTrail())
                {
                    methodCall = node as MethodCallExpression;
                    if (methodCall != null)
                    {
                        modelReference = this.GetModelReferenceForNode(node);
                        if (modelReference != null)
                        {
                            var method     = methodCall.Method;
                            var sourceType = method.GetParameters()[0]
                                             .ParameterType.FindGenericType(typeof(IEnumerable <>));
                            var resultType = method.ReturnType
                                             .FindGenericType(typeof(IEnumerable <>));
                            if (sourceType == resultType)
                            {
                                var typeOfT = sourceType.GetGenericArguments()[0];
                                if (parameter.Type == typeOfT)
                                {
                                    modelReference = new CollectionElementReference(modelReference);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            var member = this.VisitedNode as MemberExpression;

            if (member != null)
            {
                modelReference = this.GetModelReferenceForNode(member.Expression);
                if (modelReference != null)
                {
                    modelReference = new PropertyDataReference(
                        modelReference, member.Member.Name);
                }
            }

            return(modelReference);
        }
Esempio n. 2
0
        private QueryModelReference ComputeModelReference()
        {
            QueryModelReference modelReference = null;

            var methodCall = this.VisitedNode as MethodCallExpression;
            if (methodCall != null)
            {
                var method = methodCall.Method;
                if (method.DeclaringType == typeof(DataSourceStubs) &&
                    method.Name != MethodNameOfDataSourceStubValue)
                {
                    modelReference = ComputeDataSourceStubReference(methodCall);
                }
                else if (method.GetCustomAttributes<ExtensionAttribute>().Any())
                {
                    var thisModelReference = this.GetModelReferenceForNode(
                        methodCall.Arguments[0]);
                    if (thisModelReference != null)
                    {
                        modelReference = ComputeDerivedDataReference(
                            methodCall, thisModelReference);
                    }
                }
            }

            var parameter = this.VisitedNode as ParameterExpression;
            if (parameter != null)
            {
                foreach (var node in this.GetExpressionTrail())
                {
                    methodCall = node as MethodCallExpression;
                    if (methodCall != null)
                    {
                        modelReference = this.GetModelReferenceForNode(node);
                        if (modelReference != null)
                        {
                            var method = methodCall.Method;
                            var sourceType = method.GetParameters()[0]
                                .ParameterType.FindGenericType(typeof(IEnumerable<>));
                            var resultType = method.ReturnType
                                .FindGenericType(typeof(IEnumerable<>));
                            if (sourceType == resultType)
                            {
                                var typeOfT = sourceType.GetGenericArguments()[0];
                                if (parameter.Type == typeOfT)
                                {
                                    modelReference = new CollectionElementReference(modelReference);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            var member = this.VisitedNode as MemberExpression;
            if (member != null)
            {
                modelReference = this.GetModelReferenceForNode(member.Expression);
                if (modelReference != null)
                {
                    modelReference = new PropertyDataReference(
                        modelReference, member.Member.Name);
                }
            }

            return modelReference;
        }