1

次のコードのように呼び出すことができるサードパーティコンポーネントのメソッドがあります。

ICustomer log = Axis.GetInstance<ICustomer>();

上記のサードパーティコンポーネントをすべての呼び出し元に直接公開したくないので、サードパーティ「Axis.GetInstance()」を呼び出すラッパーメソッドを作成することにしました。私の問題は、タイプTを渡して、一般的なメソッド内のメソッド

呼び出しコード:

var result = Util.MyCustomWrapper<ICustomer>();


public class Util
{
  public static T MyCustomWrapper<T>()
  {

    1.call Axis.GetInstance<T>(); // **how to pass the type T**
    2.return T

  }
}
4

2 に答える 2

3

メソッドは、記述したとおりに呼び出すことができます。

public static T MyCustomWrapper<T>()
{
    return Axis.GetInstance<T>();
}
于 2012-09-14T22:36:41.437 に答える
0
public class Util
{
    public static T MyCustomWrapper<T>()
    {
        T customer = Axis.GetInstance<T>(); 
        return customer;
    }
}

さらに、コンパイルする他のタイプ

public interface ICustomer { }
public class Axis
{
    public static T GetInstance<T>() 
    {
        throw new NotImplementedException();
    }
}
于 2012-09-14T22:41:11.777 に答える