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

Fat*_*tie -2 c# generics

这是c#中通用方法的典型示例:

ParseObject po;

int i = po.Get<int>("someField");
string s = po.Get<string>("anotherField");
Run Code Online (Sandbox Code Playgroud)

我想写一个像这样工作的扩展 ...

 int i = po.ExampleGet<int>("someField");
 string i = po.ExampleGet<string>("anotherField");
Run Code Online (Sandbox Code Playgroud)

所以,

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

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

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

Ale*_*kov 5

可能您正在寻找扩展方法:

static public class Extensions
{
  static T ExampleGet<T>(this ParseObject po, string name)
  {
      return po.Get<T>(name);
  }
}
Run Code Online (Sandbox Code Playgroud)