本文整理汇总了C#中System.Linq.Expressions.MethodCallExpression.GetMethodArgument方法的典型用法代码示例。如果您正苦于以下问题:C# MethodCallExpression.GetMethodArgument方法的具体用法?C# MethodCallExpression.GetMethodArgument怎么用?C# MethodCallExpression.GetMethodArgument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.MethodCallExpression
的用法示例。
在下文中一共展示了MethodCallExpression.GetMethodArgument方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitMethodCall
protected override Expression VisitMethodCall(MethodCallExpression expression)
{
// TODO: Support TryResolve (Type/Key, <T>/Key), GetAll(), and TryGetAll()
// Intercept calls to Resolve() and Resolve<>() on the input parameter and try to handle the method call by replacing it with something "faster"
if (expression.IsMethod<IResolver, object>(resolver => resolver.Resolve((Type)null)))
{
// Resolve(Type)
var typeArg = expression.GetMethodArgument<Type>(0);
return HandleMethodCall(typeArg) ?? base.VisitMethodCall(expression);
}
if (expression.IsMethod<IResolver, object>(resolver => resolver.Resolve((Type)null, (object)null)))
{
// Resolve(Type, Key)
var typeArg = expression.GetMethodArgument<Type>(0);
var keyArg = expression.GetMethodArgument<object>(1);
return HandleMethodCall(typeArg, keyArg) ?? base.VisitMethodCall(expression);
}
if (expression.IsMethod<IResolver, object>(resolver => resolver.Resolve<object>(), replaceGenericReturnType: true))
{
// Resolve<T>()
var genericType = expression.Type;
return HandleMethodCall(genericType) ?? base.VisitMethodCall(expression);
}
if (expression.IsMethod<IResolver, object>(resolver => resolver.Resolve<object>((object)null), replaceGenericReturnType: true))
{
// Resolve<T>(Key)
var genericType = expression.Type;
var keyArg = expression.GetMethodArgument<object>(0);
return HandleMethodCall(genericType, keyArg) ?? base.VisitMethodCall(expression);
}
return base.VisitMethodCall(expression);
}