public override object ProvideValue(IServiceProvider serviceProvider) { bool ignoreIsNull = IgnoreValue == null; bool defaultIsNull = DefaultValue == null; bool configItemIsNull = ConfigManager[Key] == null; //Prevent Default = Ignore if (!ignoreIsNull && !defaultIsNull && IgnoreValue.Equals(DefaultValue)) { throw new Exception("IgnoreValue must not be equal DefaultValue"); } // If ConfigurationItem does not exist, Set to Default if (configItemIsNull) { ConfigManager[Key] = new ConfigurationItem(Key, DefaultValue); } // If Ignore != null, ConfigurationItem Exists, and ConfigurationItem Value == Ignore, Set to Default else if (!ignoreIsNull && ConfigManager[Key].Value.Equals(IgnoreValue)) { ConfigManager[Key] = new ConfigurationItem(Key, DefaultValue); } Binding binding = new Binding { Source = ConfigManager, Path = new PropertyPath(string.Format("[{0}].Value", Key)), Mode = BindingMode.TwoWay, }; return(binding.ProvideValue(serviceProvider)); }
/// <summary> /// 附加复选项目列表,文本/值。 /// </summary> /// <param name="items">复选框项目列表实例。</param> protected override void Init(IDictionary <string, object?> items) { Type?type = null; if (For != null && For.Model is IEnumerable array) { type = For.ModelExplorer.ModelType.GetElementType(); Value = array.OfType <Enum>().ToArray(); } else if (IgnoreValue != null) { type = IgnoreValue.GetType(); } else if (IgnoreValues != null) { type = IgnoreValues.First().GetType(); } else if (Value is not null) { type = Value.First().GetType(); } if (type != null) { Init(items, type); } else { throw new Exception(Resources.EnumDropdownListTagHelper_TypeNotFound); } }
/// <summary> /// 附加复选项目列表,文本/值。 /// </summary> /// <param name="items">复选框项目列表实例。</param> protected override void Init(IDictionary <string, object?> items) { if (For != null) { Init(items, For.ModelExplorer.ModelType); Value = For.Model as Enum; } else if (IgnoreValue != null) { Init(items, IgnoreValue.GetType()); } else if (Value is Enum value) { Init(items, value.GetType()); } else { throw new Exception(Resources.EnumDropdownListTagHelper_TypeNotFound); } }
public virtual string GetPropertyValue(PropertyInfo property, object obj) { object propertyValue = property.GetValue(obj); string propertyString = propertyValue.ToString(); if (!string.IsNullOrEmpty(FormatString)) { propertyString = string.Format("{0:" + FormatString + "}", propertyValue); } if (IgnoreValue != null && IgnoreValue.Equals(propertyValue)) { return(string.Empty); } if (Uppercase) { propertyString = propertyString.ToUpper(); } return(propertyString); }