要求:
扩展方法类必须为静态类;
拓展方法必须为静态方法,参数为this+需拓展类对象;
多个类拓展方法可以写在一个拓展类中;
public class TestExtension
{
public string Test1()
{
return "test";
}
}
public static class MyExtension
{
public static void Show(this TestExtension obj)
{
Debug.Log("ExtensionFunc:"+ obj.Test1());
}
}
调用:
TestExtension ts = new TestExtension();
ts.Show();