Пример #1
0
        public static ControllerSettings GetControllerSettings(ApplicationSettingsBase settings, Type controllerType)
        {
            if (controllerType == null)
            {
                return(null);
            }

            string propKey      = controllerType.FullName;
            Type   settingsType = Controllers.GetControllerSettingsType(controllerType);

            if (settingsType == null)
            {
                return(null);
            }

            // Add entry for custom settings property (required for it to be accessable)
            var prop = new SettingsProperty(propKey);

            prop.DefaultValue = null;
            prop.IsReadOnly   = false;
            prop.PropertyType = settingsType;  // Must match the actual type being used for it to serialize properly
            prop.Provider     = settings.Providers["LocalFileSettingsProvider"];
            prop.Attributes.Add(typeof(System.Configuration.UserScopedSettingAttribute), new System.Configuration.UserScopedSettingAttribute());
            prop.SerializeAs               = SettingsSerializeAs.Xml;
            prop.ThrowOnErrorSerializing   = true;
            prop.ThrowOnErrorDeserializing = true;
            try
            {
                settings.Properties.Add(prop);
                settings.Reload();
            }
            catch (System.ArgumentException) { } // Ignore if it's already been added

            // Load the settings for the specific controller
            var conf = settings[propKey];

            if (conf == null)
            {
                // Set defaults
                conf = (ControllerSettings)Activator.CreateInstance(settingsType);
                settings[propKey] = conf;
                settings.Save();
            }

            return((ControllerSettings)conf);
        }
Пример #2
0
 public override string ToString()
 {
     return(Controllers.GetControllerName(Controller));
 }