title: C# Singleton dictionary class
body: <p>I have the following class which loads a large, static XML file into an dictionary. I want it to only load it the XML once when referenced. </p>
  
  <pre><code>public class MyClass
  {
  
      private static readonly string _xmlfile = $"{path.db}database.xml";
  
      public Dictionary&lt;string, MyXML&gt; content;
  
      public MyClass()
      {
  
          var d = XMLHelper.Deserialize&lt;MyXMLs&gt;(_xmlfile);
  
          content = d.content;
  
      }
  
  }
  </code></pre>
  
  <p>I tried following the main function from this article <a href="https://www.codeproject.com/Articles/14026/Generic-Singleton-Pattern-using-Reflection-in-C" rel="nofollow noreferrer">https://www.codeproject.com/Articles/14026/Generic-Singleton-Pattern-using-Reflection-in-C</a></p>
  
  <p>But couldnt quite translate is to the Dictionary</p>