私は次のものを持っています。
public interface IMyService<T>
where T: BaseModelType
{
Process(T input);
}
public class BaseModelType
{
...some property
}
public class SomeClass : BaseModelType
{
...some properties
}
public ServiceImpl : IMyService<SomeClass>
{
...the properties
}
次に、ジェネリックインターフェイスのすべての実装を登録するユニティコンテナがあります。unitycontainerのresolveメソッドを使用してインターフェースを取得し、それに対していくつかの作業を実行できるようにしたいと思います。Resolveメソッドを使用したいときは、実行時にタイプがあります
new UnityContainer.Resolve(myTypeVar)
どういうわけかこれをキャストできますか
IMyService<BaseModelType> value = new UnityContainer.Resolve(myTypeVar) //want to cast it here from object.
インターフェイスが定義するProcessメソッドを呼び出すことができるようにします。