Sven F.

My feedback

  1. 1,024 votes
    Sign in
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      You have left! (?) (thinking…)
      19 comments  ·  Visual Studio IDE » Languages - C#  ·  Flag idea as inappropriate…  ·  Admin →
      Sven F. commented  · 

      Here is a possible solution to static extension methods. It does not apply to all needs, but may be convenient for some cases.

      To extend classes (which are defined in external libraries) with static methods just use inheritance and name the class the same as the original, but use your own namespace which will be favored by the compiler.

      Example: I wanted to extend value conversion for XML with object handling. This is what I did:

      namespace MyNamespace

      public class XmlConvert : System.Xml.XmlConvert
      public static string ToString(object value) {...}
      public static object Parse(string value, System.Type targetType) {...}


      Now when I use "XmlConvert" it will point to the newly defined class but will still show all the static methods of the original System.Xml.XmlConvert.

    Feedback and Knowledge Base