Пример #1
0
        /// <summary>
        /// 导入别的UserSettings的属性值,如果类别或属性名称不存在,则忽略
        /// </summary>
        /// <param name="srcSettings"></param>
        private void ImportProperties(UserSettings srcSettings)
        {
            foreach (UserSettingsCategory category in this.Categories)
            {
                UserSettingsCategory srcCategory = srcSettings.Categories[category.Name];

                if (srcCategory != null)
                {
                    category.ImportProperties(srcCategory);
                }
            }
        }
        internal void ImportProperties(UserSettingsCategory srcCategory)
        {
            foreach (PropertyValue property in this.Properties)
            {
                PropertyValue srcProperty = srcCategory.Properties[property.Definition.Name];

                if (srcProperty != null)
                {
                    property.StringValue = srcProperty.StringValue;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 得到属性值,如果类别或属性名称不存在,则返回缺省值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="category">类别名称</param>
        /// <param name="propName">属性名称</param>
        /// <param name="defaultValue">缺省值</param>
        /// <returns></returns>
        public T GetPropertyValue <T>(string categoryName, string propName, T defaultValue)
        {
            categoryName.CheckStringIsNullOrEmpty("categoryName");
            propName.CheckStringIsNullOrEmpty("propName");

            T result = defaultValue;

            UserSettingsCategory category = this.Categories[categoryName];

            if (category != null)
            {
                result = category.Properties.GetValue(propName, defaultValue);
            }

            return(result);
        }