Esempio n. 1
0
                public override void SetAt(MigrationContainer container, int index, TItem item)
                {
                    var list = GetList(container);

                    if (null == list)
                    {
                        return;
                    }
                    list[index] = item;
                }
Esempio n. 2
0
                public override void Accept(MigrationContainer container, IPropertyVisitor visitor)
                {
                    var context = new VisitContext <TValue> {
                        Property = this, Value = GetValue(container), Index = -1
                    };

                    if (!visitor.ExcludeOrCustomVisit(container, context))
                    {
                        visitor.Visit(container, context);
                    }
                }
Esempio n. 3
0
        /// <summary>
        /// Creates a new dynamic migration container
        /// </summary>
        /// <param name="name">Name of the new property to create</param>
        public MigrationContainer CreateContainer(string name)
        {
            if (null != m_PropertyBag.FindProperty(name))
            {
                throw new Exception($"{nameof(MigrationContainer)}.{nameof(CreateContainer)} property already exists with the `{name}`");
            }

            var container = new MigrationContainer();

            m_Data[name] = container;
            m_PropertyBag.AddProperty(DynamicProperties.CreateValueProperty(name, typeof(MigrationContainer)));

            return(container);
        }
Esempio n. 4
0
                public override TItem GetAt(MigrationContainer container, int index)
                {
                    if (m_Property is IListStructProperty)
                    {
                        return(TypeConversion.Convert <TItem>(((IListStructProperty)m_Property).GetObjectAt(ref container.m_Container, index)));
                    }

                    if (m_Property is IListClassProperty)
                    {
                        return(TypeConversion.Convert <TItem>(((IListClassProperty)m_Property).GetObjectAt(container.m_Container, index)));
                    }

                    return(default(TItem));
                }
Esempio n. 5
0
        /// <summary>
        /// Gets a container property wrapped as a `MigrationContainer`
        /// </summary>
        /// <param name="name">Name of the property to get</param>
        public MigrationContainer GetContainer(string name)
        {
            var property = m_PropertyBag.FindProperty(name);

            if (null == property)
            {
                throw new Exception($"{nameof(MigrationContainer)}.{nameof(GetContainer)} no property found with the name `{name}`");
            }

            // @TODO Type check

            MigrationContainer container;

            if (m_Data.ContainsKey(name))
            {
                // The value has already been moved to dynamic storage
                var value = m_Data[name];
                Assert.IsTrue(value is IPropertyContainer);

                if (value is MigrationContainer)
                {
                    // Already been promoted to a `MigrationContainer` return the value
                    return((MigrationContainer)m_Data[name]);
                }

                // This value exists in dynamic storage but NOT as a `MigrationContainer`
                // This can happen if the property was renamed
                container    = new MigrationContainer(value as IPropertyContainer);
                m_Data[name] = container;
                m_PropertyBag.ReplaceProperty(name, DynamicProperties.CreateValueProperty(name, typeof(MigrationContainer)));
            }
            else
            {
                // The value has not been moved to dynamic storage
                var backing = (property as IValueProperty)?.GetObjectValue(this) as IPropertyContainer;
                Assert.IsNotNull(backing);

                // Wrap the value in a `MigrationContainer` and store in dynamic storage
                container    = new MigrationContainer(backing);
                m_Data[name] = container;
                m_PropertyBag.ReplaceProperty(name, DynamicProperties.CreateValueProperty(name, typeof(MigrationContainer)));
            }

            return(container);
        }
Esempio n. 6
0
                public override void Accept(MigrationContainer container, IPropertyVisitor visitor)
                {
                    var listContext = new VisitContext <IList <TItem> >
                    {
                        Property = this,
                        Value    = null,
                        Index    = -1
                    };

                    if (visitor.ExcludeOrCustomVisit(container, listContext))
                    {
                        return;
                    }

                    if (visitor.BeginCollection(container, listContext))
                    {
                        var itemVisitContext = new VisitContext <TItem>
                        {
                            Property = this
                        };

                        for (var i = 0; i < Count(container); i++)
                        {
                            var item = GetAt(container, i);

                            itemVisitContext.Value = item;
                            itemVisitContext.Index = i;

                            if (visitor.ExcludeOrCustomVisit(container, itemVisitContext))
                            {
                                continue;
                            }

                            if (visitor.BeginContainer(container, itemVisitContext))
                            {
                                item?.Visit(visitor);
                            }
                            visitor.EndContainer(container, itemVisitContext);
                        }
                    }

                    visitor.EndCollection(container, listContext);
                }
Esempio n. 7
0
        /// <summary>
        /// Renames a property
        /// </summary>
        /// <param name="name">Name of the property to rename</param>
        /// <param name="newName">New name for the property</param>
        public MigrationContainer Rename(string name, string newName)
        {
            var property = m_PropertyBag.FindProperty(name);

            if (null == property)
            {
                throw new MigrationException($"{nameof(MigrationContainer)}.{nameof(Rename)} no property found with the name `{name}`");
            }

            if (null != m_PropertyBag.FindProperty(newName))
            {
                throw new MigrationException($"{nameof(MigrationContainer)}.{nameof(Rename)} property already exists with name `{newName}`");
            }

            var valueProperty = property as IValueProperty;

            if (null != valueProperty)
            {
                var value     = (property as IValueProperty).GetObjectValue(this);
                var valueType = valueProperty.ValueType;

                // If needed we promote this object to a migration container
                // This is because we don't support strongly typed dynamic containers (only MigrationContainers)
                if (typeof(IPropertyContainer).IsAssignableFrom(valueProperty.ValueType))
                {
                    value     = new MigrationContainer(value as IPropertyContainer);
                    valueType = typeof(MigrationContainer);
                }

                // Setup the backing storage for the value
                m_Data[newName] = value;
                m_PropertyBag.ReplaceProperty(name, DynamicProperties.CreateValueProperty(newName, valueType));

                // Clear old dynamic value if any
                if (m_Data.ContainsKey(name))
                {
                    m_Data.Remove(name);
                }
            }

            return(this);
        }
Esempio n. 8
0
                public override void Accept(MigrationContainer container, IPropertyVisitor visitor)
                {
                    var value = GetObjectValue(container) as IPropertyContainer;

                    var context = new VisitContext <IPropertyContainer>
                    {
                        Property = this,
                        Value    = value,
                        Index    = -1
                    };

                    if (visitor.ExcludeOrCustomVisit(container, context))
                    {
                        return;
                    }

                    if (visitor.BeginContainer(container, context))
                    {
                        value?.Visit(visitor);
                    }
                    visitor.EndContainer(container, context);
                }
Esempio n. 9
0
                public override void Accept(MigrationContainer container, IPropertyVisitor visitor)
                {
                    var list = GetList(container);

                    var listContext = new VisitContext <IList <TItem> >
                    {
                        Property = this,
                        Value    = list,
                        Index    = -1
                    };

                    if (visitor.ExcludeOrCustomVisit(container, listContext))
                    {
                        return;
                    }

                    if (visitor.BeginCollection(container, listContext))
                    {
                        var itemVisitContext = new VisitContext <TItem>
                        {
                            Property = this
                        };

                        for (var i = 0; i < Count(container); i++)
                        {
                            itemVisitContext.Value = TypeConversion.Convert <TItem>(list[i]);
                            itemVisitContext.Index = i;

                            if (false == visitor.ExcludeOrCustomVisit(container, itemVisitContext))
                            {
                                visitor.Visit(container, itemVisitContext);
                            }
                        }
                    }

                    visitor.EndCollection(container, listContext);
                }
Esempio n. 10
0
 public override void SetValue(MigrationContainer container, TValue value)
 {
     container.m_Data[Name] = value;
 }
Esempio n. 11
0
                public override TValue GetValue(MigrationContainer container)
                {
                    var value = container.m_Data[Name];

                    return(TypeConversion.Convert <TValue>(value));
                }
Esempio n. 12
0
 public override void SetValue(MigrationContainer container, TValue value)
 {
     (m_Property as IValueClassProperty)?.SetObjectValue(container.m_Container, value);
     (m_Property as IValueStructProperty)?.SetObjectValue(ref container.m_Container, value);
 }
Esempio n. 13
0
 public override TItem AddNew(MigrationContainer container)
 {
     throw new NotImplementedException();
 }
Esempio n. 14
0
 public override int Count(MigrationContainer container)
 {
     return(GetList(container)?.Count ?? 0);
 }
Esempio n. 15
0
 public override void Clear(MigrationContainer container)
 {
     (m_Property as IListStructProperty)?.Clear(ref container.m_Container);
     (m_Property as IListClassProperty)?.Clear(container.m_Container);
 }
Esempio n. 16
0
 public override void Insert(MigrationContainer container, int index, TItem value)
 {
     throw new NotImplementedException();
 }
Esempio n. 17
0
 public override int IndexOf(MigrationContainer container, TItem value)
 {
     throw new NotImplementedException();
 }
Esempio n. 18
0
 public override void RemoveAt(MigrationContainer container, int index)
 {
     throw new NotImplementedException();
 }
Esempio n. 19
0
 public override bool Remove(MigrationContainer container, TItem item)
 {
     throw new NotImplementedException();
 }
Esempio n. 20
0
 public override int Count(MigrationContainer container)
 {
     return(m_Property.Count(container.m_Container));
 }
Esempio n. 21
0
 private MigrationList <TItem> GetList(MigrationContainer container)
 {
     return(container.m_Data[Name] as MigrationList <TItem>);
 }
Esempio n. 22
0
 public override bool Remove(MigrationContainer container, TItem item)
 {
     GetList(container)?.Remove(item);
     return(false);
 }
Esempio n. 23
0
 public override bool Contains(MigrationContainer container, TItem item)
 {
     return(GetList(container)?.Contains(item) ?? false);
 }
Esempio n. 24
0
 public override int IndexOf(MigrationContainer container, TItem value)
 {
     return(GetList(container)?.IndexOf(value) ?? -1);
 }
Esempio n. 25
0
 public override void Add(MigrationContainer container, TItem item)
 {
     GetList(container)?.Add(item);
 }
Esempio n. 26
0
                public override TValue GetValue(MigrationContainer container)
                {
                    var value = m_Property.GetObjectValue(container.m_Container);

                    return(TypeConversion.Convert <TValue>(value));
                }
Esempio n. 27
0
 public override void RemoveAt(MigrationContainer container, int index)
 {
     GetList(container)?.RemoveAt(index);
 }
Esempio n. 28
0
 public override void SetAt(MigrationContainer container, int index, TItem item)
 {
     (m_Property as IListStructProperty)?.SetObjectAt(ref container.m_Container, index, item);
     (m_Property as IListClassProperty)?.SetObjectAt(container.m_Container, index, item);
 }
Esempio n. 29
0
 public override void Insert(MigrationContainer container, int index, TItem value)
 {
     GetList(container)?.Insert(index, value);
 }
Esempio n. 30
0
 public override void Add(MigrationContainer container, TItem item)
 {
     (m_Property as IListStructProperty)?.AddObject(ref container.m_Container, item);
     (m_Property as IListClassProperty)?.AddObject(container.m_Container, item);
 }