+
+ void CreateSettingsProperty (PropertyInfo prop, SettingsPropertyCollection properties, ref LocalFileSettingsProvider 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 ();
+ 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);
+ }