Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要向现有类型添加一个额外的方法。
例如,我需要向 XmlDocument 类型添加一个附加方法“Transfer”,例如doc.AppendChild():
doc.AppendChild()
您不能将方法添加到现有类型(至少在不重写程序集的 IL 的情况下不能),但您可以提供一个扩展方法,该方法至少看起来像该类的方法。