110,533
社区成员
发帖
与我相关
我的任务
分享
static class MyExtensionMethods
{
internal static void Print(this Class1 c)
{
}
}
public static class 未开源第三方静态类
{
public static void Method1(){}
public static void Method2(){}
public static void Method3(){}
// ...类里有几十个静态方法
}
public static class 扩展类
{
public static void Method1()
{
未开源第三方静态类.Method1();
}
public static void Method2()
{
未开源第三方静态类.Method2();
}
public static void Method3()
{
未开源第三方静态类.Method3();
}
// ...调用几十个静态方法
}
我要为这个类添加几个方法。静态类又无法继承,如果自己写个类,调用几十个同名方法感觉有点蠢,所以问问有没有其他方法。
using System;
using System.Collections.Generic;
using System.Text;
namespace 拓展方法
{
class Program
{
static void Main(string[] args)
{
Class1 class1 = new Class1();
class1.Add("");
}
}
public class Class1
{
private string str;
public string Str { get; set; }
public Class1()
{ }
}
public static class ClassAdd
{
public static void Add(this Class1 class1, string str)
{
class1.Str += str;
}
}
}
static class MyExtensionMethods
{
internal static void Print()
{
Class1.XXXX(); // 不需要引用
}
}
Partial
public artial static void MethodName()
{
//todo
}