示例#1
0
        /// <summary>
        /// Copies the value within the setting property onto the option 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 CopySettingToOption(Settings settingsClass, object optionClass)
        {
            var settingValue = SettingProperty.GetValue(settingsClass);

            // 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 = (MemberTypeSetting)(string)settingValue;

                // Note: No need to do an equality comparison before assignment as all options already have that through the Bindable base class.
                OptionProperty.SetValue(optionClass, optionValue);
            }
            else
            {
                var optionValue = (TO)settingValue;

                // Note: No need to do an equality comparison before assignment as all options already have that through the Bindable base class.
                OptionProperty.SetValue(optionClass, optionValue);
            }
        }
示例#2
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);
                }
            }
        }