Expression続き

 object型の拡張メソッドにしてしまえばいつでも使えるだろう。

public static class Reflector{
  public static TReturn InvokeInterface<TReturn>(this object obj, Expression<Func<TReturn>> expr);
}

Hoge2 hoge2 = new Hoge2();

string str = hoge2.InvokeInterface(() => (hoge2 as IHoge).Method());

 どうも使いづらい。hoge2で呼び出したんだからhoge2と書かなくても済むべきだ。

string str = hoge2.InvokeInterface( (IHoge hoge) => hoge.Method());

 こんな感じの方がよさそうだ。