将方法添加到内置类中

时间:2013-04-10 13:24:13

标签: c# c#-4.0

我需要为现有类型添加其他方法。

例如,我需要在类型XmlDocument中添加一个额外的方法“Transfer”,如doc.AppendChild()

enter image description here

1 个答案:

答案 0 :(得分:4)

您不能将方法添加到现有类型(至少在没有重写程序集的IL的情况下),但是您可以提供extension method,它至少看起来像该类的方法。