Пример #1
0
        /// <summary>
        /// Sets the configuration defaults.
        /// </summary>
        public static void SetConfigDefaults()
        {
            var properties = typeof(ProgConfig).GetProperties();

            foreach (var prop in properties)
            {
                ConfigDescription cd = (ConfigDescription)Attribute.GetCustomAttribute(prop, typeof(ConfigDescription));
                if (cd != null)
                {
                    prop.SetValue(null, cd.Default);
                }
            }
        }
Пример #2
0
        public static object GetDefaultPropertyValue(string name)
        {
            object ret  = null;
            var    prop = typeof(ProgConfig).GetProperty(name);

            if (prop != null)
            {
                ConfigDescription cd = (ConfigDescription)Attribute.GetCustomAttribute(prop, typeof(ConfigDescription));
                if (cd != null)
                {
                    ret = cd.Default;
                }
            }

            return(ret);
        }
Пример #3
0
        public static Dictionary <string, ConfigEntryInfo> GetConfig()
        {
            Dictionary <string, ConfigEntryInfo> config = new Dictionary <string, ConfigEntryInfo> ();

            var properties = typeof(ProgConfig).GetProperties();

            foreach (var prop in properties)
            {
                ConfigDescription cd = (ConfigDescription)Attribute.GetCustomAttribute(prop, typeof(ConfigDescription));
                if (cd != null)
                {
                    config.Add(prop.Name, new ConfigEntryInfo {
                        Name         = prop.Name,
                        Value        = prop.GetValue(null),
                        Type         = prop.PropertyType.Name,
                        Description  = cd != null ? cd.Description : "",
                        DefaultValue = cd?.Default,
                    });
                }
            }

            return(config);
        }