c#泛型函数-另一个泛型函数的扩展

c#泛型函数-另一个泛型函数的扩展,c#,generics,C#,Generics,下面是c#中泛型方法的典型示例: parseobjectpo; int i=采购订单获取(“someField”); 字符串s=po.Get(“另一个字段”); 我想写一个扩展,它将像这样工作 int i = po.ExampleGet<int>("someField"); string i = po.ExampleGet<string>("anotherField"); inti=po.ExampleGet(“someField”); 字符串i=po.Examp

下面是c#中泛型方法的典型示例:

parseobjectpo;
int i=采购订单获取(“someField”);
字符串s=po.Get(“另一个字段”);
我想写一个扩展,它将像这样工作

 int i = po.ExampleGet<int>("someField");
 string i = po.ExampleGet<string>("anotherField");
inti=po.ExampleGet(“someField”);
字符串i=po.ExampleGet(“另一个字段”);
所以

(a) 扩展ExampleGet必须能够以与ParseObject.Get相同的方式接受,并且

(b) 扩展ExampleGet必须能够调用ParseObject.Get(以及执行其他工作)


这样的n扩展的语法是什么,它以这种方式使用泛型?

您可能正在寻找:

静态公共类扩展
{
静态T ExampleGet(此ParseObject po,字符串名称)
{
返回采购订单获取(名称);
}
}

啊,太棒了。我每天都使用扩展(谢天谢地)——我不理解泛型的语法。明亮的
 int i = po.ExampleGet<int>("someField");
 string i = po.ExampleGet<string>("anotherField");
static public class Extensions
{
  static T ExampleGet<T>(this ParseObject po, string name)
  {
      return po.Get<T>(name);
  }
}