Beispiel #1
0
        async Task <IEntity> Deserialize(string serialized)
        {
            var data = JsonConvert.DeserializeObject <Dictionary <string, string> >(serialized);

            var result = (await Database.GetOrDefault(data["ID"], DomainType))?.Clone();

            if (result == null)
            {
                result = DomainType.CreateInstance <IEntity>();
            }

            foreach (var field in data)
            {
                var property = DomainType.GetProperty(field.Key);
                if (property.PropertyType.IsA <IEntity>())
                {
                    property = property.DeclaringType.GetProperty(property.Name + "Id");
                }

                property.SetValue(result, field.Value.To(property.PropertyType));
            }

            return(result);
        }