Ejemplo n.º 1
0
        /// <summary>
        /// Copies the value within the option property onto the setting property.
        /// </summary>
        /// <param name="settingsClass">The class instance for the settings property.</param>
        /// <param name="optionClass">The class instance for the option property.</param>
        public void CopyOptionToSetting(Settings settingsClass, object optionClass)
        {
            // Special case handling for MemberTypeSetting as operator casts for generics don't work as expected.
            if (typeof(TS) == typeof(string) && typeof(TO) == typeof(MemberTypeSetting))
            {
                var optionValue  = (string)(MemberTypeSetting)OptionProperty.GetValue(optionClass);
                var settingValue = (string)SettingProperty.GetValue(settingsClass);

                if (!EqualityComparer <string> .Default.Equals(optionValue, settingValue))
                {
                    SettingProperty.SetValue(settingsClass, optionValue);
                }
            }
            else
            {
                var optionValue  = (TS)OptionProperty.GetValue(optionClass);
                var settingValue = (TS)SettingProperty.GetValue(settingsClass);

                if (!EqualityComparer <TS> .Default.Equals(optionValue, settingValue))
                {
                    SettingProperty.SetValue(settingsClass, optionValue);
                }
            }
        }