Exemple #1
0
        //internal IEnumerable<Property> ForeignKeys
        //{
        //    get
        //    {
        //        return Properties.Where(x => x.IsForeignKey);
        //    }
        //}

        internal void SetValuesFromStorage(Backer instance, IEnumerable <Container> storage)
        {
            //if (HasParent)
            //    Parent.SetValuesFromStorage(instance, storage);

            foreach (var value in storage.Single(x => x.About.Type == ModlName).Values)
            {
                var property = GetPropertyFromModlName(value.Key);

                if (property.IsId)
                {
                    continue;
                }

                if (property.IsLink)
                {
                    var linkedDefinition = Definitions.Get((property as LinkProperty).LinkedModlType);
                    var linkIdType       = linkedDefinition.HasIdProperty ? linkedDefinition.IdProperty.PropertyType : typeof(Guid);
                    var newValue         = Materializer.DeserializeObject(value.Value, typeof(List <>).MakeGenericType(linkIdType), Settings.Get(Type));

                    var list = ((IEnumerable)newValue).Cast <object>();
                    instance.GetRelation(property.PropertyName).Set(list.Select(x => Identity.FromId(x, linkedDefinition)));
                }
                else
                {
                    var newValue = value.Value;

                    if (value.Value != null && !property.PropertyType.IsInstanceOfType(value.Value))
                    {
                        newValue = Materializer.DeserializeObject(value.Value, property.PropertyType, Settings.Get(Type));
                    }

                    instance.SetValue(property.PropertyName, newValue);
                }
            }
        }