title: C# converting string data representation to typed
body: <p>Now Im writing a universal method for loading configuration data from XML. A lot of parameters in my case are stored in node attributes, so I decided to write a universal method for attribute reading:  </p>
  
  <pre><code>    private static T ReadAttribute&lt;T&gt;(XElement Element,string AttributeName)
      {
          var attrib = Element.Attribute(AttributeName);
  
          if (attrib != null)
          {
              return attrib.Value; // off cource error is in this line !
          }
          else
          {
              return default(T);
          }
      }
  </code></pre>
  
  <p>This method should try to read attribute with specified name and if this attribute missed it should return default value for attribute type.  Attribute type is specified by T.
  As it shown in comment above my problem is that I cant universally convert string value into specific type. Actually I plan use int, double and two enum types as T.<br>
  What way I should act in this situation? How I should convert string value into T type?<br>
  Thanks in advance!</p>