Is there a way to derive from a class with an internal constructor?

后端 未结 6 427
遥遥无期
遥遥无期 2020-12-20 13:19

I\'m working with a 3rd party c# class that has lots of great methods and properties - but as time has gone by I need to extend that class with methods and properties of my

6条回答
  •  旧时难觅i
    2020-12-20 13:35

    Sounds like a perfect application for extension methods:

    MSDN extension method docs

    "Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type."

提交回复
热议问题