Ejemplo n.º 1
0
 public void AddObject(ref IPropertyContainer container, object item)
 {
     (container as IStructPropertyContainer <TContainer>)?.MakeRef((ref TContainer c, Locals l) => { l.Property.Add(ref c, l.Item); },
                                                                   new Locals {
         Property = this, Item = TypeConversion.Convert <TItem>(item)
     });
 }
Ejemplo n.º 2
0
 public bool ContainsObject(ref IPropertyContainer container, object item)
 {
     return((container as IStructPropertyContainer <TContainer>).MakeRef((ref TContainer c, Locals l) => l.Property.Contains(ref c, l.Item),
                                                                         new Locals {
         Property = this, Item = TypeConversion.Convert <TItem>(item)
     }));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts a property to the given type
        /// </summary>
        /// <param name="name">Name of the property to convert</param>
        /// <param name="type">Type to convert to</param>
        /// <param name="defaultValue">Default value to use if conversion fails</param>
        public MigrationContainer ConvertValueOrDefault(string name, Type type, object defaultValue = null)
        {
            var property = m_PropertyBag.FindProperty(name);

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

            // @TODO Type check

            // Grab the existing value
            var value = (property as IValueProperty)?.GetObjectValue(this);

            // Setup the backing storage for the value
            if (null != value)
            {
                // Try to convert the object to the new type. If this fails, fallback to the defaultValue
                m_Data[name] = TypeConversion.Convert(value, type) ?? defaultValue;
            }
            else
            {
                // @NOTE We do NOT assign the default value in this path since the value might have been explicitly set to null
                m_Data[name] = null;
            }

            // Replace the property with a newly generated one of the correct type
            m_PropertyBag.ReplaceProperty(name, DynamicProperties.CreateValueProperty(name, type));

            return(this);
        }
Ejemplo n.º 4
0
 public void SetObjectAt(ref IPropertyContainer container, int index, object item)
 {
     (container as IStructPropertyContainer <TContainer>)?.MakeRef((ref TContainer c, Locals l) => { l.Property.SetAt(ref c, l.Index, l.Item); },
                                                                   new Locals {
         Property = this, Index = index, Item = TypeConversion.Convert <TItem>(item)
     });
 }
Ejemplo n.º 5
0
 public void SetObjectValue(ref IPropertyContainer container, object value)
 {
     (container as IStructPropertyContainer <TContainer>)?.MakeRef((ref TContainer c, Locals l) =>
     {
         l.Property.SetValue(ref c, l.Value);
     }, new Locals {
         Property = this, Value = TypeConversion.Convert <TValue>(value)
     });
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the property value as the given type
        /// </summary>
        /// <param name="name">Name of the property to get the value from</param>
        public TValue GetValue <TValue>(string name)
        {
            var property = m_PropertyBag.FindProperty(name);

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

            // @TODO Type check

            return(TypeConversion.Convert <TValue>((property as IValueProperty)?.GetObjectValue(this)));
        }
Ejemplo n.º 7
0
        public TValue GetValueOrDefault <TValue>(string name, TValue defaultValue = default(TValue))
        {
            var property = m_PropertyBag.FindProperty(name);

            if (null == property)
            {
                return(defaultValue);
            }

            // @TODO Type check

            return(TypeConversion.Convert <TValue>((property as IValueProperty)?.GetObjectValue(this)));
        }
Ejemplo n.º 8
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));
                }
Ejemplo 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);
                }
        public void InsertObject(IPropertyContainer container, int index, object item)
        {
            var c = (TContainer)container;

            Insert(ref c, index, TypeConversion.Convert <TItem>(item));
        }
        public void InsertObject(IPropertyContainer container, int index, object item)
        {
            var list = GetValue((TContainer)container);

            list.Insert(index, TypeConversion.Convert <TItem>(item));
        }
Ejemplo n.º 12
0
 public void SetObjectValue(TContainer container, object value)
 {
     SetValue(container, TypeConversion.Convert <TValue>(value));
 }
Ejemplo n.º 13
0
        public static TValue GetValue <TValue>(this IPropertyContainer container, string name)
        {
            var value = (container.PropertyBag.FindProperty(name) as IValueProperty)?.GetObjectValue(container);

            return(TypeConversion.Convert <TValue>(value));
        }
 void IListProperty.SetObjectAt(IPropertyContainer container, int index, object value)
 {
     SetItemAt((TContainer)container, index, TypeConversion.Convert <TItem>(value));
 }
Ejemplo n.º 15
0
                public override MigrationContainer GetValue(MigrationContainer container)
                {
                    var value = container.m_Data[Name];

                    return(TypeConversion.Convert <MigrationContainer>(value));
                }
Ejemplo n.º 16
0
                public override TValue GetValue(MigrationContainer container)
                {
                    var value = m_Property.GetObjectValue(container.m_Container);

                    return(TypeConversion.Convert <TValue>(value));
                }
        public void AddObject(IPropertyContainer container, object item)
        {
            var c = (TContainer)container;

            Add(ref c, TypeConversion.Convert <TItem>(item));
        }
Ejemplo n.º 18
0
 public bool ContainsObject(IPropertyContainer container, object item)
 {
     return(Contains((TContainer)container, TypeConversion.Convert <TItem>(item)));
 }
 public void AddObject(IPropertyContainer container, object item)
 {
     Add((TContainer)container, TypeConversion.Convert <TItem>(item));
 }
Ejemplo n.º 20
0
 public void SetObjectAt(IPropertyContainer container, int index, object item)
 {
     SetAt((TContainer)container, index, TypeConversion.Convert <TItem>(item));
 }
Ejemplo n.º 21
0
 public virtual void SetObjectValue(IPropertyContainer container, object value)
 {
     SetValue((TContainer)container, TypeConversion.Convert <TValue>(value));
 }
Ejemplo n.º 22
0
 public override TItem GetAt(MigrationContainer container, int index)
 {
     return(TypeConversion.Convert <TItem>(GetList(container)[index]));
 }