internal SettingInfo(PropertyInfo info, ApplicationSettingCollection settingCollection, SettingAttribute settingAttribute) { PropertyInfo = info; Info = settingAttribute; Name = info.Name; FriendlyName = StringLoader.GetString(Name).CoalesceNullOrEmpty(Name); ValueRepresent = info.GetCustomAttribute <ValueRepresentAttribute>(); var pType = info.PropertyType; if (ValueRepresent is null) { if (!typeDic.TryGetValue(pType, out type)) { if (pType == typeof(bool)) { ValueRepresent = ToggleSwitchRepresentAttribute.Default; } else if (pType.GetTypeInfo().IsEnum) { ValueRepresent = EnumRepresentAttribute.Default; } else { throw new InvalidOperationException($"Unsupported property type: {{{pType}}}"); } } } settingCollection.PropertyChanged += settingsChanged; this.settingCollection = settingCollection; }
public string GetFriendlyNameOf(string name) { if (ReferenceEquals(this, Default)) { return(name); } return(StringLoader.GetString($"{this.ResourcePrefix}/{name}")); }
public ToggleSwitchRepresentAttribute(string trueStringKey, string falseStringKey) { this.TrueString = StringLoader.GetString(trueStringKey); this.FalseString = StringLoader.GetString(falseStringKey); }