コード例 #1
0
 /// <summary>
 ///     Identifies methods as instances of known sequence operators.
 /// </summary>
 /// <param name="method"> Method info to identify </param>
 /// <param name="sequenceMethod"> Identified sequence operator </param>
 /// <returns>
 ///     <c>true</c> if method is known; <c>false</c> otherwise
 /// </returns>
 internal static bool TryIdentifySequenceMethod(MethodInfo method, out SequenceMethod sequenceMethod)
 {
     method = method.IsGenericMethod
                  ? method.GetGenericMethodDefinition()
                  : method;
     return(_methodMap.TryGetValue(method, out sequenceMethod));
 }
コード例 #2
0
        private static bool HasPredicateArgument(MethodCallExpression callExpression, out int argumentOrdinal)
        {
            SequenceMethod method;

            argumentOrdinal = 0;
            bool flag = false;

            if ((2 <= callExpression.Arguments.Count) && ReflectionUtil.TryIdentifySequenceMethod(callExpression.Method, out method))
            {
                SequenceMethod method2 = method;
                if (method2 <= SequenceMethod.SkipWhileOrdinal)
                {
                    switch (method2)
                    {
                    case SequenceMethod.Where:
                    case SequenceMethod.WhereOrdinal:
                    case SequenceMethod.TakeWhile:
                    case SequenceMethod.TakeWhileOrdinal:
                    case SequenceMethod.SkipWhile:
                    case SequenceMethod.SkipWhileOrdinal:
                        goto Label_00B4;

                    case SequenceMethod.Skip:
                        return(flag);
                    }
                    return(flag);
                }
                switch (method2)
                {
                case SequenceMethod.FirstPredicate:
                case SequenceMethod.FirstOrDefaultPredicate:
                case SequenceMethod.LastPredicate:
                case SequenceMethod.LastOrDefaultPredicate:
                case SequenceMethod.SinglePredicate:
                case SequenceMethod.SingleOrDefaultPredicate:
                case SequenceMethod.AnyPredicate:
                case SequenceMethod.All:
                case SequenceMethod.CountPredicate:
                case SequenceMethod.LongCountPredicate:
                    goto Label_00B4;

                case SequenceMethod.FirstOrDefault:
                case SequenceMethod.Last:
                case SequenceMethod.LastOrDefault:
                case SequenceMethod.Single:
                case SequenceMethod.SingleOrDefault:
                    return(flag);

                case SequenceMethod.Count:
                case SequenceMethod.LongCount:
                    return(flag);
                }
            }
            return(flag);

Label_00B4:
            argumentOrdinal = 1;
            return(true);
        }
コード例 #3
0
 internal static bool IsAnyAllMethod(SequenceMethod sequenceMethod)
 {
     if ((sequenceMethod != SequenceMethod.Any) && (sequenceMethod != SequenceMethod.AnyPredicate))
     {
         return(sequenceMethod == SequenceMethod.All);
     }
     return(true);
 }
コード例 #4
0
        internal static bool IsSequenceMethod(MethodInfo method, SequenceMethod sequenceMethod)
        {
            bool           result;
            SequenceMethod foundSequenceMethod;

            if (TryIdentifySequenceMethod(method, out foundSequenceMethod))
            {
                result = foundSequenceMethod == sequenceMethod;
            }
            else
            {
                result = false;
            }

            return(result);
        }
コード例 #5
0
 internal static bool TryIdentifySequenceMethod(
     Expression expression,
     bool unwrapLambda,
     out SequenceMethod sequenceMethod)
 {
     if (expression.NodeType == ExpressionType.Lambda && unwrapLambda)
     {
         expression = ((LambdaExpression)expression).Body;
     }
     if (expression.NodeType == ExpressionType.Call)
     {
         return(ReflectionUtil.TryIdentifySequenceMethod(((MethodCallExpression)expression).Method, out sequenceMethod));
     }
     sequenceMethod = SequenceMethod.Where;
     return(false);
 }
コード例 #6
0
 /// <summary>
 ///     Looks up some implementation of a sequence method.
 /// </summary>
 /// <param name="sequenceMethod"> Sequence method to find </param>
 /// <param name="method"> Known method </param>
 /// <returns> true if some method is found; false otherwise </returns>
 internal static bool TryLookupMethod(SequenceMethod sequenceMethod, out MethodInfo method)
 {
     return _inverseMap.TryGetValue(sequenceMethod, out method);
 }
コード例 #7
0
        /// <summary>
        ///     Identifies method call expressions as calls to known sequence operators.
        /// </summary>
        /// <param name="expression"> Expression that may represent a call to a known sequence method </param>
        /// <param name="unwrapLambda">
        ///     If <c>true</c> , and the <paramref name="expression" /> argument is a LambdaExpression, the Body of the LambdaExpression argument will be retrieved, and that expression will then be examined for a sequence method call instead of the Lambda itself.
        /// </param>
        /// <param name="sequenceMethod"> Identified sequence operator </param>
        /// <returns>
        ///     <c>true</c> if <paramref name="expression" /> is a <see cref="MethodCallExpression" /> and its target method is known; <c>false</c> otherwise
        /// </returns>
        internal static bool TryIdentifySequenceMethod(Expression expression, bool unwrapLambda, out SequenceMethod sequenceMethod)
        {
            if (expression.NodeType == ExpressionType.Lambda && unwrapLambda)
            {
                expression = ((LambdaExpression)expression).Body;
            }

            if (expression.NodeType
                == ExpressionType.Call)
            {
                var methodCall = (MethodCallExpression)expression;
                return TryIdentifySequenceMethod(methodCall.Method, out sequenceMethod);
            }

            sequenceMethod = default(SequenceMethod);
            return false;
        }
コード例 #8
0
 /// <summary>
 ///     Identifies methods as instances of known sequence operators.
 /// </summary>
 /// <param name="method"> Method info to identify </param>
 /// <param name="sequenceMethod"> Identified sequence operator </param>
 /// <returns>
 ///     <c>true</c> if method is known; <c>false</c> otherwise
 /// </returns>
 internal static bool TryIdentifySequenceMethod(MethodInfo method, out SequenceMethod sequenceMethod)
 {
     method = method.IsGenericMethod
                  ? method.GetGenericMethodDefinition()
                  : method;
     return _methodMap.TryGetValue(method, out sequenceMethod);
 }
コード例 #9
0
ファイル: ReflectionUtil.cs プロジェクト: nickchal/pash
 internal static bool IsSequenceMethod(MethodInfo method, SequenceMethod sequenceMethod)
 {
     SequenceMethod method2;
     return (TryIdentifySequenceMethod(method, out method2) && (method2 == sequenceMethod));
 }
コード例 #10
0
ファイル: ReflectionUtil.cs プロジェクト: nickchal/pash
 internal static bool IsAnyAllMethod(SequenceMethod sequenceMethod)
 {
     if ((sequenceMethod != SequenceMethod.Any) && (sequenceMethod != SequenceMethod.AnyPredicate))
     {
         return (sequenceMethod == SequenceMethod.All);
     }
     return true;
 }
コード例 #11
0
 private SequenceExpression(string name, SequenceMethod method) : base(name, MethodType.Function)
 {
     this.Method = method;
 }
コード例 #12
0
        internal static bool IsSequenceMethod(MethodInfo method, SequenceMethod sequenceMethod)
        {
            bool result;
            SequenceMethod foundSequenceMethod;
            if (TryIdentifySequenceMethod(method, out foundSequenceMethod))
            {
                result = foundSequenceMethod == sequenceMethod;
            }
            else
            {
                result = false;
            }

            return result;
        }
コード例 #13
0
ファイル: ReflectionUtil.cs プロジェクト: TomDu/odata.net
 /// <summary>
 /// Check to see if this is an Any or an All method
 /// </summary>
 /// <param name="sequenceMethod">sequence method to check.</param>
 /// <returns>true if sequence method is Any or All, false otherwise.</returns>
 internal static bool IsAnyAllMethod(SequenceMethod sequenceMethod)
 {
     return sequenceMethod == SequenceMethod.Any ||
            sequenceMethod == SequenceMethod.AnyPredicate ||
            sequenceMethod == SequenceMethod.All;
 }
コード例 #14
0
        internal static bool IsSequenceMethod(MethodInfo method, SequenceMethod sequenceMethod)
        {
            SequenceMethod method2;

            return(TryIdentifySequenceMethod(method, out method2) && (method2 == sequenceMethod));
        }
コード例 #15
0
        /// <summary>
        ///     Identifies method call expressions as calls to known sequence operators.
        /// </summary>
        /// <param name="expression"> Expression that may represent a call to a known sequence method </param>
        /// <param name="unwrapLambda">
        ///     If <c>true</c> , and the <paramref name="expression" /> argument is a LambdaExpression, the Body of the LambdaExpression argument will be retrieved, and that expression will then be examined for a sequence method call instead of the Lambda itself.
        /// </param>
        /// <param name="sequenceMethod"> Identified sequence operator </param>
        /// <returns>
        ///     <c>true</c> if <paramref name="expression" /> is a <see cref="MethodCallExpression" /> and its target method is known; <c>false</c> otherwise
        /// </returns>
        internal static bool TryIdentifySequenceMethod(Expression expression, bool unwrapLambda, out SequenceMethod sequenceMethod)
        {
            if (expression.NodeType == ExpressionType.Lambda && unwrapLambda)
            {
                expression = ((LambdaExpression)expression).Body;
            }

            if (expression.NodeType
                == ExpressionType.Call)
            {
                var methodCall = (MethodCallExpression)expression;
                return(TryIdentifySequenceMethod(methodCall.Method, out sequenceMethod));
            }

            sequenceMethod = default(SequenceMethod);
            return(false);
        }
コード例 #16
0
 /// <summary>
 ///     Looks up some implementation of a sequence method.
 /// </summary>
 /// <param name="sequenceMethod"> Sequence method to find </param>
 /// <param name="method"> Known method </param>
 /// <returns> true if some method is found; false otherwise </returns>
 internal static bool TryLookupMethod(SequenceMethod sequenceMethod, out MethodInfo method)
 {
     return(_inverseMap.TryGetValue(sequenceMethod, out method));
 }
コード例 #17
0
 internal virtual Predicate Translate(PredicateConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
 {
     return(Translate(parent, call));
 }