Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 public string GetFriendlyNameOf(string name)
 {
     if (ReferenceEquals(this, Default))
     {
         return(name);
     }
     return(StringLoader.GetString($"{this.ResourcePrefix}/{name}"));
 }
Ejemplo n.º 3
0
 public ToggleSwitchRepresentAttribute(string trueStringKey, string falseStringKey)
 {
     this.TrueString  = StringLoader.GetString(trueStringKey);
     this.FalseString = StringLoader.GetString(falseStringKey);
 }