Sven F.Sven F.

My feedback

  1. 955 votes
    Vote
    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      You have left! (?) (thinking…)
      17 comments  ·  Visual Studio IDE » Languages - C#  ·  Flag idea as inappropriate…  ·  Admin →
      Sven F.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