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) }); }
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) })); }
/// <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); }
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) }); }
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) }); }
/// <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))); }
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))); }
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)); }
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)); }
public void SetObjectValue(TContainer container, object value) { SetValue(container, TypeConversion.Convert <TValue>(value)); }
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)); }
public override MigrationContainer GetValue(MigrationContainer container) { var value = container.m_Data[Name]; return(TypeConversion.Convert <MigrationContainer>(value)); }
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)); }
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)); }
public void SetObjectAt(IPropertyContainer container, int index, object item) { SetAt((TContainer)container, index, TypeConversion.Convert <TItem>(item)); }
public virtual void SetObjectValue(IPropertyContainer container, object value) { SetValue((TContainer)container, TypeConversion.Convert <TValue>(value)); }
public override TItem GetAt(MigrationContainer container, int index) { return(TypeConversion.Convert <TItem>(GetList(container)[index])); }