title: Deserialize objectstring convert string to bool
body: <p>I have a class, which object I serialize to an XML string. no prob.</p>
  
  <p>Deserializing also works but it sets a field that is the XML "true" to false (probably because it can not convert to boolean true.</p>
  
  <p>So I decorated that property with</p>
  
  <pre><code>public class X 
  {
      // ...
      private bool _status = false;
      [XmlText]
      public bool Status {
          get {return _status;}
          set {_status=value;}
      }
      // ...
  }
  </code></pre>
  
  <p>However then I get "xmlserializer - there was an error reflecting type X" ...</p>
  
  <p>So what is the workaround other than replace all my checks against a string Status instead?</p>
  
  <p>ref:
  - <a href="https://stackoverflow.com/questions/60573/xmlserializer-there-was-an-error-reflecting-type">XmlSerializer - There was an error reflecting type</a>
  - <a href="https://stackoverflow.com/questions/11798281/deserialize-boolean-element-with-string-attribute">Deserialize boolean element with string attribute</a></p>
  
  <p><strong>update on request:</strong>
  The serialize/deserialize class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  // for serializer:
  using System.Xml;
  using System.Xml.Serialization;
  using System.IO;
  
  namespace StackOverflow
  {
  
      static class Serializing
      {
          public static T XmlDeserializeFromString&lt;T&gt;(this string objectData)
          {
              return (T)XmlDeserializeFromString(objectData, typeof(T));
          }
  
          public static object XmlDeserializeFromString(this string objectData, Type type)
          {
              var serializer = new XmlSerializer(type);
              object result;
  
              using (TextReader reader = new StringReader(objectData))
              {
                  result = serializer.Deserialize(reader);
              }
  
              return result;
          }
  
          public static string Serialize&lt;T&gt;(this T value)
          {
              if (value == null) { return string.Empty; }
              try
              {
                  var xmlserializer = new XmlSerializer(typeof(User));
                  var stringWriter = new StringWriter();
                  using (var writer = XmlWriter.Create(stringWriter))
                  {
                      xmlserializer.Serialize(writer, value);
                      return stringWriter.ToString();
                  }
              }
              catch (Exception e)
              {
                  throw new Exception("A Serialization Error Occurred", e);
              }
          }
      }
  }
  </code></pre>