title: Alternative to being able to define static extension methods
body: <p>I understand that I can't extend static classes in C#, I don't <em>really</em> understand the reason why, but I do understand <em>that</em> it can't be done.</p>
  
  <p>So, with that in mind, here is what I wanted to achieve:</p>
  
  <pre><code>public static class GenericXmlSerialisationExtender
  {
      public static void WriteToXML&lt;T&gt;(this T targetObject, string fileName)
      {
          XmlSerializer serializer = new XmlSerializer(typeof(T));
          using (TextWriter writer = new StreamWriter(fileName, false, Encoding.UTF8))
          {
              serializer.Serialize(writer, targetObject);
          }
      }
  
      public static T ReadFromXML&lt;T&gt;(string fileName)
      {
          XmlSerializer serializer = new XmlSerializer(typeof(T));
          using (TextReader reader = new StreamReader(fileName, Encoding.UTF8))
          {
              return (T)serializer.Deserialize(reader);
          }
      }
  }
  </code></pre>
  
  <p>I.e. I wanted to define .WriteToXML for instances (there are quite a lot of config / static data classes which I need to use which just use vanilla XML Serialization), and then .ReadFromXML for types.</p>
  
  <p>So effectively I could call something like:</p>
  
  <pre><code>MyType typeInstance = MyType.ReadFromXML(path_to_data);
  </code></pre>
  
  <p>What would be the 'proper' way of encapsulating that? I once worked with a colleague who believed 'code re-use' was copy &amp; paste, and I'd rather not put myself in that bracket!</p>