Пример #1
0
        /// <summary>
        /// Creates a new list of values property
        /// </summary>
        public MigrationList <TItem> CreateValueList <TItem>(string name)
        {
            var property = m_PropertyBag.FindProperty(name);

            if (null != property)
            {
                throw new Exception($"{nameof(MigrationContainer)}.{nameof(CreateValueList)} property already exists with the name `{name}`");
            }

            m_Data[name] = new MigrationList <TItem>();
            m_PropertyBag.AddProperty(DynamicProperties.CreateListProperty <TItem>(name));

            return(m_Data[name] as MigrationList <TItem>);
        }
Пример #2
0
        /// <summary>
        /// Gets an existing list of containers
        /// </summary>
        /// <param name="name"></param>
        public MigrationList <MigrationContainer> GetContainerList(string name)
        {
            var property = m_PropertyBag.FindProperty(name);

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

            // @TODO Type check

            var listProperty = property as IListClassProperty;

            Assert.IsNotNull(listProperty);

            MigrationList <MigrationContainer> list;

            if (m_Data.ContainsKey(name))
            {
                list = m_Data[name] as MigrationList <MigrationContainer>;

                if (null == list)
                {
                    throw new Exception($"{nameof(MigrationContainer)}.{nameof(GetValueList)} expected type of `{typeof(MigrationList<MigrationContainer>)} but found `{m_Data[name].GetType()}`");
                }
            }
            else
            {
                list = new MigrationList <MigrationContainer>();

                for (var i = 0; i < listProperty.Count(this); i++)
                {
                    list.Add(new MigrationContainer(listProperty.GetObjectAt(this, i) as IPropertyContainer));
                }

                m_Data[name] = list;
                m_PropertyBag.ReplaceProperty(name, DynamicProperties.CreateListProperty <MigrationContainer>(name));
            }

            return(list);
        }