0

I looked an the MethodCallExpression object for extension method and found that

  • the Object property is null and
  • the Arguments[0].NodeType is MemberAccess

are those two parameters enough to say that this method call is an extension method?


Here's some test code (updated):

as @Rob suggested it might be just a static method and indeed there is no differce between those two calls

void Main()
{
    var abc = "abc";
    Bar(() => abc.Foo());
    Bar(() => Baz(abc));
}

static void Bar<T>(Expression<Func<T>> expr)
{
    var methodCallExpression = expr.Body as MethodCallExpression;
}

static string Baz(string s)
{
    return "baz";
}

static class Ext
{
    public static string Foo(this string s)
    {
        return "foo";
    }
}
t3chb0t
  • 16,340
  • 13
  • 78
  • 118

0 Answers0