title: Check if XElement is null globally
body: <p>I have a class what takes care of reading and holding the XML file.
  Right now a simple version of it looks like this:</p>
  
  <pre><code>public class EstEIDPersoConfig
  {
      public bool LaunchDebugger { get ; set; }
      public string Password { get; set; }
      public int Slot { get; set; }
      public string Reader { get; set; }
      public string TestInput { get; set; }
      public bool Logging { get; set; }
  
      public EstEIDPersoConfig()
      {
          XElement xml = XElement.Load(myxml.xml);
          XElement Configuration = xml.Element("Configuration");
  
          LaunchDebugger = Convert.ToBoolean(Configuration.Element("LaunchDebugger").Value);
          Password = Configuration.Element("Password").Value;
          Slot = Convert.ToInt32(Configuration.Element("Slot").Value);
          Reader = Configuration.Element("Reader").Value;
          TestInput = Configuration.Element("TestInput").Value;
          Logging = Convert.ToBoolean(Configuration.Element("Logging").Value);
       }
   }
  </code></pre>
  
  <p>And there will be more later. so the problem is that if some element does not exist in xml i get <code>System.NullReferenceException</code>. So i need to check if the element is <code>null</code> or not. Heres one way to do this:</p>
  
  <pre><code>var value = Configuration.Element("LaunchDebugger").Value;
  if (value != null)
      LaunchDebugger = Convert.ToBoolean(value);
  else
      throw new Exception("LaunchDebugger element missing from xml!");
  </code></pre>
  
  <p>But doing that for every element would be just too much. So i need some good ideas how to simplify this system so it wouldn't end up in 1000 lines of code.</p>
  
  <p>EDIT: Edited the last code snippet, the idea was not to set a default value, idea was to notify the user that this element whats null is missing from the xml.</p>