+ [MonoTODO]
+ public override object this [ string propertyName ] {
+ get {
+ if (IsSynchronized) {
+ lock (this) {
+ return GetPropertyValue (propertyName);
+ }
+ }
+
+ return GetPropertyValue (propertyName);
+ }
+ set {
+ SettingsProperty prop = Properties [ propertyName ];
+
+ if (prop == null)
+ throw new SettingsPropertyNotFoundException (propertyName);
+
+ if (prop.IsReadOnly)
+ throw new SettingsPropertyIsReadOnlyException (propertyName);
+
+ /* XXX check the type of the property vs the type of @value */
+ if (value != null &&
+ !prop.PropertyType.IsAssignableFrom (value.GetType()))
+ throw new SettingsPropertyWrongTypeException (propertyName);
+
+ if (PropertyValues [ propertyName ] == null)
+ CacheValuesByProvider (prop.Provider);
+
+ SettingChangingEventArgs changing_args = new SettingChangingEventArgs (propertyName,
+ GetType().FullName,
+ settingsKey,
+ value,
+ false);
+
+ OnSettingChanging (this, changing_args);
+
+ if (changing_args.Cancel == false) {
+ /* actually set the value */
+ PropertyValues [ propertyName ].PropertyValue = value;
+
+ /* then emit PropertyChanged */
+ OnPropertyChanged (this, new PropertyChangedEventArgs (propertyName));
+ }
+ }
+ }
+
+#if (CONFIGURATION_DEP)
+ [Browsable (false)]
+ public override SettingsPropertyCollection Properties {
+ get {
+ if (IsSynchronized)
+ Monitor.Enter (this);
+
+ try {
+ if (properties == null) {
+ SettingsProvider local_provider = null;
+
+ properties = new SettingsPropertyCollection ();
+
+ Type this_type = GetType();
+ SettingsProviderAttribute[] provider_attrs = (SettingsProviderAttribute[])this_type.GetCustomAttributes (typeof (SettingsProviderAttribute), false);;
+ if (provider_attrs != null && provider_attrs.Length != 0) {
+ Type provider_type = Type.GetType (provider_attrs[0].ProviderTypeName);
+ SettingsProvider provider = (SettingsProvider) Activator.CreateInstance (provider_type);
+ provider.Initialize (null, null);
+ if (provider != null && Providers [provider.Name] == null) {
+ Providers.Add (provider);
+ local_provider = provider;
+ }
+ }
+
+ PropertyInfo[] type_props = this_type.GetProperties ();
+ foreach (PropertyInfo prop in type_props) { // only public properties
+ SettingAttribute[] setting_attrs = (SettingAttribute[])prop.GetCustomAttributes (typeof (SettingAttribute), false);
+ if (setting_attrs == null || setting_attrs.Length == 0)
+ continue;
+ CreateSettingsProperty (prop, properties, ref local_provider);
+ }
+ }
+
+ return properties;
+ } finally {
+ if (IsSynchronized)
+ Monitor.Exit (this);
+ }
+ }
+ }
+
+ void CreateSettingsProperty (PropertyInfo prop, SettingsPropertyCollection properties, ref SettingsProvider local_provider)
+ {
+ SettingsAttributeDictionary dict = new SettingsAttributeDictionary ();
+ SettingsProvider provider = null;
+ object defaultValue = null;
+ SettingsSerializeAs serializeAs = SettingsSerializeAs.String;
+ bool explicitSerializeAs = false;
+
+ foreach (Attribute a in prop.GetCustomAttributes (false)) {
+ /* the attributes we handle natively here */
+ if (a is SettingsProviderAttribute) {
+ Type provider_type = Type.GetType (((SettingsProviderAttribute)a).ProviderTypeName);
+ provider = (SettingsProvider) Activator.CreateInstance (provider_type);
+ provider.Initialize (null, null);
+ }
+ else if (a is DefaultSettingValueAttribute) {
+ defaultValue = ((DefaultSettingValueAttribute)a).Value;
+ }
+ else if (a is SettingsSerializeAsAttribute) {
+ serializeAs = ((SettingsSerializeAsAttribute)a).SerializeAs;
+ explicitSerializeAs = true;
+ }
+ else if (a is ApplicationScopedSettingAttribute ||
+ a is UserScopedSettingAttribute) {
+ dict.Add (a.GetType(), a);
+ }
+ else {
+ dict.Add (a.GetType(), a);
+ }
+ }
+
+ if (!explicitSerializeAs) {
+ // DefaultValue is a string and if we can't convert from string to the
+ // property type then the only other option left is for the string to
+ // be XML.
+ //
+ TypeConverter converter = TypeDescriptor.GetConverter (prop.PropertyType);
+ if (converter != null &&
+ (!converter.CanConvertFrom (typeof (string)) ||
+ !converter.CanConvertTo (typeof (string))))
+ serializeAs = SettingsSerializeAs.Xml;
+ }
+
+ SettingsProperty setting =
+ new SettingsProperty (prop.Name, prop.PropertyType, provider, false /* XXX */,
+ defaultValue /* XXX always a string? */, serializeAs, dict,
+ false, false);
+
+
+ if (providerService != null)
+ setting.Provider = providerService.GetSettingsProvider (setting);
+
+ if (provider == null) {
+ if (local_provider == null) {
+ local_provider = new LocalFileSettingsProvider () as SettingsProvider;
+ local_provider.Initialize (null, null);
+ }
+ setting.Provider = local_provider;
+ // .NET ends up to set this to providers.
+ provider = local_provider;
+ }
+
+ if (provider != null) {
+ /* make sure we're using the same instance of a
+ given provider across multiple properties */
+ SettingsProvider p = Providers[provider.Name];
+ if (p != null)
+ setting.Provider = p;
+ }
+
+ properties.Add (setting);
+
+ if (setting.Provider != null && Providers [setting.Provider.Name] == null)
+ Providers.Add (setting.Provider);
+ }
+#endif
+
+ [Browsable (false)]
+ public override SettingsPropertyValueCollection PropertyValues {
+ get {
+ if (IsSynchronized)
+ Monitor.Enter (this);
+
+ try {
+ if (propertyValues == null) {
+ propertyValues = new SettingsPropertyValueCollection ();
+ }
+
+ return propertyValues;
+ } finally {
+ if (IsSynchronized)
+ Monitor.Exit (this);
+ }
+ }
+ }
+
+ [Browsable (false)]
+ public override SettingsProviderCollection Providers {
+ get {
+ if (IsSynchronized)
+ Monitor.Enter (this);
+
+ try {
+ if (providers == null)
+ providers = new SettingsProviderCollection ();
+
+ return providers;
+ } finally {
+ if (IsSynchronized)
+ Monitor.Exit (this);
+ }
+ }
+ }
+
+ [Browsable (false)]
+ public string SettingsKey {
+ get {
+ return settingsKey;
+ }
+ set {
+ settingsKey = value;
+ }
+ }
+
+ string settingsKey;
+ SettingsContext context;
+#if (CONFIGURATION_DEP)
+ SettingsPropertyCollection properties;
+ ISettingsProviderService providerService;
+#endif
+ SettingsPropertyValueCollection propertyValues;
+ SettingsProviderCollection providers;