/// <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)); }
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); }
internal static bool IsAnyAllMethod(SequenceMethod sequenceMethod) { if ((sequenceMethod != SequenceMethod.Any) && (sequenceMethod != SequenceMethod.AnyPredicate)) { return(sequenceMethod == SequenceMethod.All); } return(true); }
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); }
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); }
/// <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); }
/// <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; }
/// <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); }
internal static bool IsSequenceMethod(MethodInfo method, SequenceMethod sequenceMethod) { SequenceMethod method2; return (TryIdentifySequenceMethod(method, out method2) && (method2 == sequenceMethod)); }
internal static bool IsAnyAllMethod(SequenceMethod sequenceMethod) { if ((sequenceMethod != SequenceMethod.Any) && (sequenceMethod != SequenceMethod.AnyPredicate)) { return (sequenceMethod == SequenceMethod.All); } return true; }
private SequenceExpression(string name, SequenceMethod method) : base(name, MethodType.Function) { this.Method = method; }
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; }
/// <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; }
internal static bool IsSequenceMethod(MethodInfo method, SequenceMethod sequenceMethod) { SequenceMethod method2; return(TryIdentifySequenceMethod(method, out method2) && (method2 == sequenceMethod)); }
/// <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); }
/// <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)); }
internal virtual Predicate Translate(PredicateConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod) { return(Translate(parent, call)); }