传递类型<t> </t>

时间:2012-09-14 22:33:09

标签: c# generics

我在第三方组件中有一个方法,可以像下面的代码一样调用:

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

  }
}

1 个答案:

答案 0 :(得分: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();
    }
}
相关问题