private T deserialize <T>(XElement xml) where T : IPersistableEntity, new() { T instance = new T(); var props = typeof(T).GetProperties().Where(x => Attribute.IsDefined(x, typeof(PersistedAttribute))); foreach (var n in xml.Nodes()) { var node = (XElement)n; var prop = props.First(x => { string name = x.Name; var attr = x.GetCustomAttribute <PersistedAttribute>(); if (attr.PersistedName != null) { name = attr.PersistedName; } return(name == node.Name); }); if (prop == null) { continue; } prop.SetValue(instance, Transformers.GetFittingTransformerFromString(prop.PropertyType)(node.Value)); /*var value = prop * .PropertyType * .GetConstructor(new[] {typeof(string)}) * ?.Invoke(new object[] {node.Value});*/ //if (value == null) continue; //prop.SetValue(instance, value); } return(instance); }