私はこのようなことをするための解決策を見つけていません。
Address クラスがあるとします
public class Address : IAddress{...}
そして、私は AddressManager クラスを持っています
public class AddressManager{
public void SaveAddress(Address adress)
{...}
}
後で、このSaveAddress()メソッド情報が MethodInfo オブジェクトに含まれるようになりました。そして、この情報から Action オブジェクトを作成できます。このような:
Action<Address> action = (Action<Address>)Delegate.CreateDelegate(typeof(Action<Address>), instance, methodInfo);
そして、次のように実行できます。
action(parameter);
それはうまくいきますが、私の問題は、Addressを「ジェネリック」にして、 IAddressを実装するものなら何でも送信できるようにすることです。
私はこのようなことをするのが好きです
Action<IAddress> action = (Action<IAddress>)Delegate.CreateDelegate(typeof(Action<IAddress>), instance, methodInfo);
action(parameter);
しかし、パラメーターとしてAddressを想定しているため、methodSignature と一致しないため、問題が発生します。
または私はこれをしたいです(私は決して可能であるとは思わない)
Action<parameter.GetType()> action = (Action<parameter.GetType()>)Delegate.CreateDelegate(typeof(Action<parameter.GetType()>), instance, methodInfo);
action(parameter);
これを処理する良い方法はありますか?