示例#1
0
        /// <summary>
        /// Returns a UserConfig object based on the checkbox configuration
        /// </summary>
        /// <param name="userConfig"></param>
        /// <returns></returns>
        private UserConfig SaveUserConfig(UserConfig userConfig = null)
        {
            if (userConfig == null)
                userConfig = new UserConfig();

            IEnumerator e = GetDictionaryCheckBoxes().GetEnumerator();
            KeyValuePair<string, CheckBox> kvp = new KeyValuePair<string, CheckBox>();

            while (e.MoveNext())
            {
                kvp = (KeyValuePair<string, CheckBox>)e.Current;
                CheckBox chk = kvp.Value as CheckBox;
                PropertyInfo[] properties = typeof(UserConfig).GetProperties();
                foreach (PropertyInfo pi in properties)
                {
                    string propName = chk.Name.Remove(0, 3);
                    if (pi.PropertyType == typeof(Boolean) && pi.Name.Equals(propName))
                    {
                        pi.SetValue(userConfig, chk.Checked, null);
                        break;
                    }
                }
            }

            return userConfig;
        }
示例#2
0
        public static bool IsConfigured(UserConfig self)
        {
            PropertyInfo[] properties = typeof(UserConfig).GetProperties();
            foreach (PropertyInfo pi in properties)
            {
                if (pi.PropertyType == typeof(Boolean) && (bool)pi.GetValue(self, null))
                {
                    return true;
                }
            }

            return false;
        }