2
0
Эх сурвалжийг харах

2007-05-30 Atsushi Enomoto <[email protected]>

	* ConfigXmlDocument.cs : added explicit interface implementations.
	* ApplicationSettingsBase.cs : split deeply-nested get_Properties()
	  into itself and a method. Treat default LocalFileSettingsProvider
	  as a (valid) settings provider. Removed a fixme (only public
	  members should be available).
	* SettingsBase.cs : check lock state in Save().
	* SettingsProviderCollection.cs : remove bogus table field which
	  conflicts with the table in base ProviderCollection class.


svn path=/trunk/mcs/; revision=78240
Atsushi Eno 18 жил өмнө
parent
commit
8b06b7c8a2

+ 78 - 74
mcs/class/System/System.Configuration/ApplicationSettingsBase.cs

@@ -250,87 +250,91 @@ namespace System.Configuration {
 
 					properties = new SettingsPropertyCollection ();
 
-					foreach (PropertyInfo prop in GetType().GetProperties (/* only public properties? */)) {
+					foreach (PropertyInfo prop in GetType ().GetProperties ()) { // only public properties
 						SettingAttribute[] setting_attrs = (SettingAttribute[])prop.GetCustomAttributes (typeof (SettingAttribute), false);
-						if (setting_attrs != null && setting_attrs.Length > 0) {
-							SettingsAttributeDictionary dict = new SettingsAttributeDictionary ();
-							SettingsProvider provider = null;
-							object defaultValue = null;
-							SettingsSerializeAs serializeAs = SettingsSerializeAs.String;
-
-							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; /* XXX this is a string.. do we convert? */
-									// note: for StringCollection, TypeDescriptor.GetConverter(prop.PropertyType) returns
-									// CollectionConverter, however this class cannot handle the XML serialized strings
-									if (prop.PropertyType == typeof(StringCollection)) {
-										XmlSerializer xs = new XmlSerializer (typeof (string[]));
-										string[] values = (string[]) xs.Deserialize (new StringReader ((string)defaultValue));
-										StringCollection sc = new StringCollection ();
-										sc.AddRange (values);
-										defaultValue = sc;
-									} else if (prop.PropertyType != typeof(string)) {
-										defaultValue = TypeDescriptor.GetConverter(prop.PropertyType).ConvertFromString((string)defaultValue);
-									}
-								}
-								else if (a is SettingsSerializeAsAttribute) {
-									serializeAs = ((SettingsSerializeAsAttribute)a).SerializeAs;
-								}
-								else if (a is ApplicationScopedSettingAttribute ||
-									 a is UserScopedSettingAttribute) {
-									dict.Add (a.GetType(), a);
-								}
-								else {
-									dict.Add (a.GetType(), a);
-								}
-							}
-
-							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;
-							}
-
-							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);
-						}
+						if (setting_attrs == null || setting_attrs.Length == 0)
+							continue;
+						CreateSettingsProperty (prop, properties, ref local_provider);
 					}
 				}
 
 				return properties;
 			}
 		}
+
+		void CreateSettingsProperty (PropertyInfo prop, SettingsPropertyCollection properties, ref LocalFileSettingsProvider local_provider)
+		{
+			SettingsAttributeDictionary dict = new SettingsAttributeDictionary ();
+			SettingsProvider provider = null;
+			object defaultValue = null;
+			SettingsSerializeAs serializeAs = SettingsSerializeAs.String;
+
+			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; /* XXX this is a string.. do we convert? */
+					// note: for StringCollection, TypeDescriptor.GetConverter(prop.PropertyType) returns
+					// CollectionConverter, however this class cannot handle the XML serialized strings
+					if (prop.PropertyType == typeof(StringCollection)) {
+						XmlSerializer xs = new XmlSerializer (typeof (string[]));
+						string[] values = (string[]) xs.Deserialize (new StringReader ((string)defaultValue));
+						StringCollection sc = new StringCollection ();
+						sc.AddRange (values);
+						defaultValue = sc;
+					} else if (prop.PropertyType != typeof(string)) {
+						defaultValue = TypeDescriptor.GetConverter(prop.PropertyType).ConvertFromString((string)defaultValue);
+					}
+				}
+				else if (a is SettingsSerializeAsAttribute) {
+					serializeAs = ((SettingsSerializeAsAttribute)a).SerializeAs;
+				}
+				else if (a is ApplicationScopedSettingAttribute ||
+					 a is UserScopedSettingAttribute) {
+					dict.Add (a.GetType(), a);
+				}
+				else {
+					dict.Add (a.GetType(), a);
+				}
+			}
+
+			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);
+if (Providers.Count == 0) throw new Exception (setting.Provider.Name + ((object) Providers [setting.Provider.Name] ?? "(null)"));
+		}
 #endif
 
 		[Browsable (false)]

+ 11 - 0
mcs/class/System/System.Configuration/ChangeLog

@@ -1,3 +1,14 @@
+2007-05-30  Atsushi Enomoto  <[email protected]>
+
+	* ConfigXmlDocument.cs : added explicit interface implementations.
+	* ApplicationSettingsBase.cs : split deeply-nested get_Properties()
+	  into itself and a method. Treat default LocalFileSettingsProvider
+	  as a (valid) settings provider. Removed a fixme (only public
+	  members should be available).
+	* SettingsBase.cs : check lock state in Save().
+	* SettingsProviderCollection.cs : remove bogus table field which
+	  conflicts with the table in base ProviderCollection class.
+
 2007-05-30  Atsushi Enomoto  <[email protected]>
 
 	* SettingsBase.cs : property values are filled only when each

+ 10 - 0
mcs/class/System/System.Configuration/ConfigXmlDocument.cs

@@ -117,6 +117,16 @@ namespace System.Configuration
 			}
 		}
 
+#if NET_2_0 && CONFIGURATION_DEP
+		string System.Configuration.Internal.IConfigErrorInfo.Filename {
+			get { return Filename; }
+		}
+
+		int System.Configuration.Internal.IConfigErrorInfo.LineNumber {
+			get { return LineNumber; }
+		}
+#endif
+
 		//
 		// Wrappers for Xml* that just provide file name and line number addition
 		//

+ 2 - 1
mcs/class/System/System.Configuration/LocalFileSettingsProvider.cs

@@ -3,8 +3,9 @@
 //
 // Authors:
 //	Chris Toshok ([email protected])
+//	Atsushi Enomoto ([email protected])
 //
-// (C) 2005 Novell, Inc (http://www.novell.com)
+// (C) 2005, 2007 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the

+ 9 - 0
mcs/class/System/System.Configuration/SettingsBase.cs

@@ -51,6 +51,15 @@ namespace System.Configuration
 		}
 
 		public virtual void Save ()
+		{
+			if (sync)
+				lock (this)
+					SaveCore ();
+			else
+				SaveCore ();
+		}
+
+		void SaveCore ()
 		{
 			//
 			// Copied from ApplicationSettingsBase

+ 4 - 5
mcs/class/System/System.Configuration/SettingsProviderCollection.cs

@@ -40,25 +40,24 @@ namespace System.Configuration
 		: ProviderCollection
 #endif
 	{
-		Hashtable providers;
-
 		public SettingsProviderCollection ()
 		{
-			providers = new Hashtable ();
 		}
 
 #if (CONFIGURATION_DEP)
 		public override void Add (ProviderBase provider)
 		{
+			if (!(provider is SettingsProvider))
+				throw new ArgumentException ("SettingsProvider is expected");
 			if (String.IsNullOrEmpty (provider.Name))
 				throw new ArgumentException ("Provider name cannot be null or empty");
-			providers.Add (provider.Name, provider);
+			base.Add (provider);
 		}
 #endif
 
 		public new SettingsProvider this [ string name ] { 
 			get {
-				return (SettingsProvider)providers [ name ];
+				return (SettingsProvider) base [ name ];
 			}
 		}
 	}