本文整理汇总了C#中System.Linq.Expressions.MethodCallExpression.GetArgument方法的典型用法代码示例。如果您正苦于以下问题:C# MethodCallExpression.GetArgument方法的具体用法?C# MethodCallExpression.GetArgument怎么用?C# MethodCallExpression.GetArgument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.MethodCallExpression
的用法示例。
在下文中一共展示了MethodCallExpression.GetArgument方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression m)
{
if (m.Method.DeclaringType == typeof(Queryable) ||
m.Method.DeclaringType == typeof(Enumerable) ||
m.Method.DeclaringType == typeof(EnumerableUniqueExtensions))
{
switch (m.Method.Name)
{
case "Where":
return this.BindWhere(m.Type, m.GetArgument("source"), m.GetArgument("predicate").StripQuotes());
case "Select":
return this.BindSelect(m.Type, m.GetArgument("source"), m.GetArgument("selector").StripQuotes());
case "SelectMany":
if (m.Arguments.Count == 2)
return this.BindSelectMany(m.Type, m.GetArgument("source"), m.GetArgument("selector").StripQuotes(), null);
else
return this.BindSelectMany(m.Type, m.GetArgument("source"), m.GetArgument("collectionSelector").StripQuotes(), m.TryGetArgument("resultSelector").StripQuotes());
case "Join":
return this.BindJoin(
m.Type, m.GetArgument("outer"), m.GetArgument("inner"),
m.GetArgument("outerKeySelector").StripQuotes(),
m.GetArgument("innerKeySelector").StripQuotes(),
m.GetArgument("resultSelector").StripQuotes());
case "OrderBy":
return this.BindOrderBy(m.Type, m.GetArgument("source"), m.GetArgument("keySelector").StripQuotes(), OrderType.Ascending);
case "OrderByDescending":
return this.BindOrderBy(m.Type, m.GetArgument("source"), m.GetArgument("keySelector").StripQuotes(), OrderType.Descending);
case "ThenBy":
return this.BindThenBy(m.GetArgument("source"), m.GetArgument("keySelector").StripQuotes(), OrderType.Ascending);
case "ThenByDescending":
return this.BindThenBy(m.GetArgument("source"), m.GetArgument("keySelector").StripQuotes(), OrderType.Descending);
case "GroupBy":
return this.BindGroupBy(m.Type, m.GetArgument("source"),
m.GetArgument("keySelector").StripQuotes(),
m.GetArgument("elementSelector").StripQuotes());
case "Count":
return this.BindCount(m.Type, m.GetArgument("source"));
case "DefaultIfEmpty":
return Visit(m.GetArgument("source"));
case "Any":
return this.BindAny(m.Type, m.GetArgument("source"));
case "All":
return this.BindAll(m.Type, m.GetArgument("source"), m.GetArgument("predicate").StripQuotes());
case "Contains":
return this.BindContains(m.Type, m.GetArgument("source"), m.TryGetArgument("item") ?? m.GetArgument("value"));
case "Sum":
case "Min":
case "Max":
case "Average":
return this.BindAggregate(m.Type, m.Method.Name.ToEnum<AggregateFunction>(),
m.GetArgument("source"), m.TryGetArgument("selector").StripQuotes());
case "First":
case "FirstOrDefault":
case "Single":
case "SingleOrDefault":
return BindUniqueRow(m.Type, m.Method.Name.ToEnum<UniqueFunction>(),
m.GetArgument("source"), m.TryGetArgument("predicate").StripQuotes());
case "FirstEx":
case "SingleEx":
case "SingleOrDefaultEx":
return BindUniqueRow(m.Type, m.Method.Name.RemoveEnd(2).ToEnum<UniqueFunction>(),
m.GetArgument("collection"), m.TryGetArgument("predicate").StripQuotes());
case "Distinct":
return BindDistinct(m.Type, m.GetArgument("source"));
case "Take":
return BindTake(m.Type, m.GetArgument("source"), m.GetArgument("count"));
case "Skip":
return BindSkip(m.Type, m.GetArgument("source"), m.GetArgument("count"));
}
}
if (m.Method.Name == "Mixin" && m.Method.GetParameters().Length == 0)
{
var obj = Visit(m.Object);
var me = obj as MetaExpression;
if (me != null && me.Meta is CleanMeta)
{
CleanMeta cm = (CleanMeta)me.Meta;
var mixinType = m.Method.GetGenericArguments().Single();
return new MetaExpression(mixinType, new CleanMeta(null, cm.PropertyRoutes.Select(a => a.Add(mixinType)).ToArray()));
}
}
if (m.Method.DeclaringType == typeof(LinqHints) || m.Method.DeclaringType == typeof(LinqHintEntities))
return Visit(m.Arguments[0]);
if (m.Method.DeclaringType == typeof(Lite) && m.Method.Name == "ToLite")
return MakeCleanMeta(m.Type, Visit(m.Arguments[0]));
if (m.Method.DeclaringType == typeof(Math) &&
(m.Method.Name == "Abs" ||
m.Method.Name == "Ceiling" ||
m.Method.Name == "Floor" ||
m.Method.Name == "Round" ||
m.Method.Name == "Truncate"))
return MakeCleanMeta(m.Type, Visit(m.Arguments[0]));
//.........这里部分代码省略.........
示例2: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression m)
{
Type decType = m.Method.DeclaringType;
if (m.Method.IsGenericMethod && (decType == typeof(Queryable) || decType == typeof(Enumerable)))
{
bool query = decType == typeof(Queryable);
Type[] paramTypes = m.Method.GetGenericArguments();
MethodInfo mi = m.Method.GetGenericMethodDefinition();
//IE<IGrouping<K, S>> GroupBy<S, K>(this IE<S> source, Func<S, K> keySelector);
// GroupBy(col, a=>func(a)) -> GroupBy(col, a=>func(a), a=>a)
if (ReflectionTools.MethodEqual(mi, miGroupBySE) || ReflectionTools.MethodEqual(mi, miGroupBySQ))
{
var source = Visit(m.GetArgument("source"));
var keySelector = (LambdaExpression)Visit(m.GetArgument("keySelector").StripQuotes());
MethodInfo miG = (query ? miGroupByNQ : miGroupByNE)
.MakeGenericMethod(paramTypes[0], paramTypes[1], paramTypes[0]);
ParameterExpression p = Expression.Parameter(paramTypes[0], "p" + i++);
return Expression.Call(miG, source, keySelector, Expression.Lambda(p, p));
}
//IE<R> GroupBy<S, K, R>(this IE<S> source, Func<S, K> keySelector, Func<K, IE<S>, R> resultSelector);
// GroupBy(col, a=>f1(a), a=>f2(a), (a,B)=>f3(a,B)) -> GroupBy(col, a=>f1(a), a=>f2(a)).Select(g=>=>f3(g.Key,g))
if (ReflectionTools.MethodEqual(mi, miGroupBySRE) || ReflectionTools.MethodEqual(mi, miGroupBySRQ))
{
var source = Visit(m.GetArgument("source"));
var keySelector = (LambdaExpression)Visit(m.GetArgument("keySelector").StripQuotes());
var resultSelector = (LambdaExpression)Visit(m.GetArgument("resultSelector").StripQuotes());
Type groupingType = typeof(IGrouping<,>).MakeGenericType(paramTypes[1], paramTypes[0]);
MethodInfo miG = (query ? miGroupByNQ : miGroupByNE)
.MakeGenericMethod(paramTypes[0], paramTypes[1], paramTypes[0]);
MethodInfo miS = (query ? miSelectQ : miSelectE)
.MakeGenericMethod(groupingType, paramTypes[2]);
ParameterExpression g = Expression.Parameter(groupingType, "g" + i++);
LambdaExpression newResult =
Expression.Lambda(
Replacer.Replace(Replacer.Replace(resultSelector.Body,
resultSelector.Parameters[0], Expression.MakeMemberAccess(g, groupingType.GetProperty("Key"))),
resultSelector.Parameters[1], g),
g);
ParameterExpression p = Expression.Parameter(paramTypes[0], "p" + i++);
return
Expression.Call(miS,
Expression.Call(miG, source, keySelector, Expression.Lambda(p, p)),
newResult);
}
//IE<R> GroupBy<S, K, E, R>(this IE<S> source, Func<S, K> keySelector, Func<S, E> elementSelector, Func<K, IE<E>, R> resultSelector)
// GroupBy(col, a=>f1(a), a=>f2(a), (k,B)=>f(k,B)) -> GroupBy(col, a=>f1(a), a=>f2(a)).Select(g=>f3(g.Key,g))
if (ReflectionTools.MethodEqual(mi, miGroupByNRE) || ReflectionTools.MethodEqual(mi, miGroupByNRQ))
{
var source = Visit(m.GetArgument("source"));
var keySelector = (LambdaExpression)Visit(m.GetArgument("keySelector").StripQuotes());
var elementSelector = (LambdaExpression)Visit(m.GetArgument("elementSelector").StripQuotes());
var resultSelector = (LambdaExpression)Visit(m.GetArgument("resultSelector").StripQuotes());
Type groupingType = typeof(IGrouping<,>).MakeGenericType(paramTypes[1], paramTypes[2]);
MethodInfo miG = (query ? miGroupByNQ : miGroupByNE)
.MakeGenericMethod(paramTypes[0], paramTypes[1], paramTypes[2]);
MethodInfo miS = (query ? miSelectQ : miSelectE)
.MakeGenericMethod(groupingType, paramTypes[3]);
ParameterExpression g = Expression.Parameter(groupingType, "g" + i++);
LambdaExpression newResult =
Expression.Lambda(
Replacer.Replace(Replacer.Replace(resultSelector.Body,
resultSelector.Parameters[0], Expression.MakeMemberAccess(g, groupingType.GetProperty("Key"))),
resultSelector.Parameters[1], g),
g);
return
Expression.Call(miS,
Expression.Call(miG, source, keySelector, elementSelector),
newResult);
}
//IE<R> GroupJoin<O, I, K, R>(this IE<O> outer, IE<I> inner, Func<O, K> outerKeySelector, Func<I, K> innerKeySelector, Func<O, IE<I>, R> resultSelector)
// GroupJoin(outer, inner, o=>f1(o), i=>f2
//(i), (o, gI)=>f3(o,gI)) -->
// Join(outer, GroupBy(inner, i=>f2(i), i=>i) , o=>f1(o), g=>g.Key, (o,g)=>f2(o, g))
//.........这里部分代码省略.........
示例3: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression node)
{
if (node.GetArgument("ae") == parameter && (node.Method.Name == "Pattern" || node.Method.Name == "TryPattern"))
return new AutomationPatternExpression(node.Method.GetGenericArguments()[0], node.Type);
return base.VisitMethodCall(node);
}