It creates a node for the property[Width] but the value is always empty. Code is below.
private static string SerializeToXml<T>(T value)
{
StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);
XmlSerializer serializer = new XmlSerializer(typeof(T));
serializer.Serialize(writer, value);
return writer.ToString();
}
private static T DeSerializeToObject<T>(string xml) where T : new()
{
try
{
T result;
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (TextReader reader = new StringReader(xml))
{
result = (T)serializer.Deserialize(reader);
}
return result;
}
catch (Exception e)
{
return new T();
}
}
public string Serialize(GridLayout layout)
{
return SerializeToXml(layout);
}
public GridLayout DeSerialize(string xml)
{
return DeSerializeToObject<GridLayout>(xml);
}
[Serializable]
[XmlInclude(typeof(Unit))]
public class ColumnLayout
{
public int OrderIndex { get; set; }
public string UniqueName { get; set; }
public string CurrentFilterValue { get; set; }
public GridKnownFunction CurrentFilterFunction { get; set; }
public string SortExpression { get; set; }
public bool Visible { get; set; }
public Unit Width { get; set; }
public string HeaderText { get; set; }
public bool IsEmpty { get; set; }
public UnitType Type { get; set; }
public double Value { get; set; }
}