public override void DataBind() { if (DataSource == null) { return; } properties = DataSource.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo property in properties) { ModulePropertyAttribute attribute = (ModulePropertyAttribute)Attribute.GetCustomAttribute(property, typeof(ModulePropertyAttribute)); if (attribute == null) { continue; } string value = Context.Request.Form[property.Name]; if (value == null) { continue; } if (PropertyValues.ContainsKey(property.Name)) { PropertyValues[property.Name] = value; } else { PropertyValues.Add(property.Name, value); } } }
public ISettingsPresetBuilder SetPropertyValue(string property, object?value) { if (!PropertyValues.ContainsKey(property)) { PropertyValues[property] = value; } return(this); }
protected T Get <T>([CallerMemberName] string propertyName = null) { if (PropertyValues.ContainsKey(propertyName)) { return((T)PropertyValues[propertyName]); } return(default(T)); }
/// <summary> /// Adds property for injection /// </summary> /// <param name="propertyName">Service property name for injection</param> /// <param name="factory">Method that is responsible for creation a value for injection</param> public void AddPropertyFactory(string propertyName, Delegate factory) { // property can be added only to one Dictionary, so we must remove from other dictionary, if it contains the property if (PropertyValues.ContainsKey(propertyName)) { PropertyValues.Remove(propertyName); } PropertySetters[propertyName] = factory; // here we just update the value }
public object GetPropertyValue(string classType, string propertyName) { if (PropertyValues.ContainsKey(classType)) { if (PropertyValues[classType].Any(x => x.PropertyName.Equals(propertyName))) { return(PropertyValues[classType].FirstOrDefault(x => x.PropertyName.Equals(propertyName)).Value); } } return(null); }
public void SetProperty(string name, object value) { Argument.Assert.IsNotNullOrEmpty(name, nameof(name)); string v = value == null ? null : value.ToString(); if (PropertyValues.ContainsKey(name)) { PropertyValues[name] = v; } else { PropertyValues.Add(name, v); } }
public void AddPropertyValue(string classType, string propertyName, object value) { if (!PropertyValues.ContainsKey(classType)) { PropertyValues.Add(classType, new List <PropertyValue>()); } if (PropertyValues[classType].Any(x => x.PropertyName.Equals(propertyName))) { PropertyValues[classType].FirstOrDefault(x => x.PropertyName.Equals(propertyName)).Value = value; } else { PropertyValues[classType].Add(new PropertyValue(propertyName, value)); } }
/// <summary> /// Sets the value of a property. If the value is different the current value of the property, <see cref="PropertyChanged"/> event is raised. /// </summary> /// <typeparam name="T">the type of the property</typeparam> /// <returns>True if the property value has been updated, otherwise false</returns> protected bool SetPropertyValue <T>(Expression <Func <T> > propertyAccessor, T value) { bool valueChanged = false; string propertyName = GetPropertyName(propertyAccessor); if (PropertyValues.ContainsKey(propertyName)) { PropertyValues.AddOrUpdate(propertyName, value, (key, previousValue) => { if (typeof(T).IsValueType) { valueChanged = previousValue == null || !previousValue.Equals(value); } else { // ReSharper disable CompareNonConstrainedGenericWithNull valueChanged = !previousValue?.Equals(value) ?? value != null; // ReSharper restore CompareNonConstrainedGenericWithNull } return(value); }); if (valueChanged) { OnPropertyChanged(propertyName); } } else { valueChanged = true; PropertyValues.AddOrUpdate(propertyName, value, (key, previousValue) => value); OnPropertyChanged(propertyName); } return(valueChanged); }
/// <summary> /// Sets the value of a property. If the value is different the current value of the property, /// <see cref="PropertyChanged" /> event is raised. /// </summary> /// <typeparam name="T">the type of the property</typeparam> /// <returns>True if the property value has been updated, otherwise false</returns> protected bool SetPropertyValue <T>(Expression <Func <T> > propertyAccessor, T value) { var valueChanged = false; var propertyName = GetPropertyName(propertyAccessor); if (PropertyValues.ContainsKey(propertyName)) { PropertyValues.AddOrUpdate(propertyName, value, (key, previousValue) => { if (typeof(T).GetTypeInfo().IsValueType) { valueChanged = previousValue == null || !previousValue.Equals(value); } else { valueChanged = !previousValue?.Equals(value) ?? value != null; } return(value); }); if (valueChanged) { OnPropertyChanged(propertyName); } } else { valueChanged = true; PropertyValues.AddOrUpdate(propertyName, value, (key, previousValue) => value); OnPropertyChanged(propertyName); } return(valueChanged); }
private Control GetEditControl(PropertyInfo property, ModulePropertyAttribute attribute) { string name = property.Name; if (PropertyValues.ContainsKey(name)) { attribute.DefaultValue = PropertyValues[name]; } PortalControl editControl = attribute.GetEditControl(property.PropertyType); editControl.ID = name; string value = Context.Request.Form[name]; if (value != null) { ITextControl textControl = editControl as ITextControl; if (textControl != null) { textControl.Text = value; return(editControl); } IListControl listControl = editControl as IListControl; if (listControl != null) { ListItem item = listControl.Items.FindByValue(value); if (item != null) { item.Selected = true; } return(editControl); } } return(editControl); }