/// <summary> /// Updates the property with the given data. If the property does not exist, it will be added.<para/> /// Any <see langword="null"/> parameters will retain their existing values. /// </summary> /// <param name="key">The property to edit.</param> /// <param name="newName">If defined, the name of the property will be changed to this.</param> /// <param name="values">The new values to set the property to.</param> /// <param name="propertyNameImage">The image displayed next to the property name.</param> /// <param name="propertyValueImages">The image displayed next to each of the values for the property.</param> /// <param name="displaySinglePropertiesInline">If true, properties with single values will be displayed in the same element containing the property name (<c>Name: Value</c>) instead of as a child element (<c>Name</c>, with a child of <c>Value</c>).</param> public void EditSimpleProperty(DataTreeObjectProperty key, string newName = null, object[] values = null, SilkImage?propertyNameImage = null, SilkImage?propertyValueImages = null, bool?displaySinglePropertiesInline = null) { key.Text = newName ?? key.Text; List <DataTreeObject> pValues = new List <DataTreeObject>(); if (values != null) { foreach (object obj in values) { if (obj == null) { continue; } if (obj is DataTreeObject objInstance) { pValues.Add(objInstance); } else if (obj is DataTreeObjectProperty prop) { pValues.Add(prop); } else { pValues.Add(new DataTreeObjectProperty(obj.ToString(), propertyValueImages.GetValueOrDefault(SilkImage.Value))); } } } key.ImageKey = propertyNameImage ?? key.ImageKey; key.DisplaySingleChildInline = displaySinglePropertiesInline ?? key.DisplaySingleChildInline; Properties[key] = pValues; }
/// <summary> /// An alias method used to add a property with a generic icon to <see cref="Properties"/> (omitting the need to create a <see cref="DataTreeObject"/>)<para/> /// If the object array contains any <see cref="DataTreeObjectProperty"/> instances, those instances will be used (and <paramref name="propertyValueImages"/> will be overridden where applicable). /// </summary> /// <param name="name">The name of the property.</param> /// <param name="values">The values displayed under the property.</param> /// <param name="propertyNameImage">The image displayed next to the property name.</param> /// <param name="propertyValueImages">The image displayed next to each of the values for the property.</param> /// <param name="displaySinglePropertiesInline">If true, properties with single values will be displayed in the same element containing the property name (<c>Name: Value</c>) instead of as a child element (<c>Name</c>, with a child of <c>Value</c>).</param> public DataTreeObjectProperty AddSimpleProperty(string name, object[] values, SilkImage propertyNameImage = SilkImage.Value, SilkImage propertyValueImages = SilkImage.Value, bool displaySinglePropertiesInline = true) { DataTreeObjectProperty propName = new DataTreeObjectProperty(name, propertyNameImage, displaySinglePropertiesInline); List <DataTreeObject> pValues = new List <DataTreeObject>(); foreach (object obj in values) { if (obj is DataTreeObject objInstance) { pValues.Add(objInstance); } else if (obj is DataTreeObjectProperty prop) { pValues.Add(prop); } else { if (obj is null) { pValues.Add(new DataTreeObjectProperty("null", propertyValueImages)); } else { pValues.Add(new DataTreeObjectProperty(obj.ToString(), propertyValueImages)); } } } Properties[propName] = pValues; return(propName); }
/// <summary> /// Updates the property with the given data.<para/> /// Any <see langword="null"/> parameters will retain their existing values. /// </summary> /// <param name="key">The property to edit.</param> /// <param name="newName">If <see langword="null"/>, the name will remain unchanged. If defined, the name of the property will be changed to this.</param> /// <param name="value">The new value to set the property to.</param> /// <param name="propertyNameImage">The image displayed next to the property name.</param> /// <param name="propertyValueImages">The image displayed next to each of the values for the property.</param> /// <param name="displaySinglePropertiesInline">If true, properties with single values will be displayed in the same element containing the property name (<c>Name: Value</c>) instead of as a child element (<c>Name</c>, with a child of <c>Value</c>).</param> public void EditSimpleProperty(DataTreeObjectProperty key, string newName = null, object value = null, SilkImage?propertyNameImage = null, SilkImage?propertyValueImages = null, bool?displaySinglePropertiesInline = null) => EditSimpleProperty(key, newName, new object[] { value }, propertyNameImage, propertyValueImages, displaySinglePropertiesInline);