Przeglądaj źródła

2007-06-21 Atsushi Enomoto <[email protected]>

	* SettingValueElement.cs : implement Reset().
	* CustomizableFileSettingsProvider.cs : fixed company name getter
	  and product name getter.
	  LoadPropertyValue() should expect null ValueXml.
	* LocalFileSettingsProvider.cs : time to switch. With a bit of
	  directory name difference, it should work.


svn path=/trunk/mcs/; revision=80469
Atsushi Eno 18 lat temu
rodzic
commit
a351e7c4ea

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

@@ -1,3 +1,12 @@
+2007-06-21  Atsushi Enomoto  <[email protected]>
+
+	* SettingValueElement.cs : implement Reset().
+	* CustomizableFileSettingsProvider.cs : fixed company name getter
+	  and product name getter.
+	  LoadPropertyValue() should expect null ValueXml.
+	* LocalFileSettingsProvider.cs : time to switch. With a bit of
+	  directory name difference, it should work.
+
 2007-06-13  Atsushi Enomoto  <[email protected]>
 
 	* CustomizableLocalFileSettingsProvider.cs :

+ 30 - 12
mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs

@@ -37,6 +37,8 @@ using System.Collections.Generic;
 using System.Configuration;
 using System.IO;
 using System.Reflection;
+using System.Security.Cryptography;
+using System.Text;
 using System.Xml;
 
 using NameValueCollection = PrebuiltSystem.System.Collections.Specialized.NameValueCollection;
@@ -220,21 +222,26 @@ namespace System.Configuration
 			set { isCompany = value; }
 		}
 
+		// AssemblyCompanyAttribute->Namespace->"Program"
 		private static string GetCompanyName ()
 		{
 			Assembly assembly = Assembly.GetEntryAssembly ();
 			if (assembly == null)
 				assembly = Assembly.GetCallingAssembly ();
-			if (assembly == null)
-				return string.Empty;
-				
+
 			AssemblyCompanyAttribute [] attrs = (AssemblyCompanyAttribute []) assembly.GetCustomAttributes (typeof (AssemblyCompanyAttribute), true);
-			
+		
 			if ((attrs != null) && attrs.Length > 0) {
 				return attrs [0].Company;
 			}
 
-			return assembly.GetName ().Name;
+			MethodInfo entryPoint = assembly.EntryPoint;
+			Type entryType = entryPoint != null ? entryPoint.DeclaringType : null;
+			if (entryType != null && entryType.Namespace.Length > 0) {
+				int end = entryType.Namespace.IndexOf ('.');
+				return end < 0 ? entryType.Namespace : entryType.Namespace.Substring (0, end);
+			}
+			return "Program";
 		}
 
 		private static string GetProductName ()
@@ -242,16 +249,26 @@ namespace System.Configuration
 			Assembly assembly = Assembly.GetEntryAssembly ();
 			if (assembly == null)
 				assembly = Assembly.GetCallingAssembly ();
-			if (assembly == null)
-				return string.Empty;
-				
+
+#if true
+
+			byte [] pkt = assembly.GetName ().GetPublicKeyToken ();
+			byte [] hash = SHA1.Create ().ComputeHash (pkt != null ? pkt : Encoding.UTF8.GetBytes (assembly.EscapedCodeBase));
+			return String.Format ("{0}_{1}_{2}",
+				AppDomain.CurrentDomain.FriendlyName,
+				pkt != null ? "StrongName" : "Url",
+				// FIXME: it seems that something else is used
+				// here, to convert hash bytes to string.
+				Convert.ToBase64String (hash));
+
+#else // AssemblyProductAttribute-based code
 			AssemblyProductAttribute [] attrs = (AssemblyProductAttribute[]) assembly.GetCustomAttributes (typeof (AssemblyProductAttribute), true);
-			
+		
 			if ((attrs != null) && attrs.Length > 0) {
 				return attrs [0].Product;
 			}
-
 			return assembly.GetName ().Name;
+#endif
 		}
 
 		private static string GetProductVersion ()
@@ -619,9 +636,10 @@ namespace System.Configuration
 
 		private void LoadPropertyValue (SettingsPropertyCollection collection, SettingElement element, bool allowOverwrite)
 		{
-			SettingsPropertyValue value = new SettingsPropertyValue (collection [element.Name]);
+			SettingsProperty prop = collection [element.Name];
+			SettingsPropertyValue value = new SettingsPropertyValue (prop);
 			value.IsDirty = false;
-			value.SerializedValue = element.Value.ValueXml.InnerText;
+			value.SerializedValue = element.Value.ValueXml != null ? element.Value.ValueXml.InnerText : prop.DefaultValue;
 			try
 			{
 				if (allowOverwrite)

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

@@ -59,12 +59,7 @@ namespace System.Configuration
 		public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context,
 										   SettingsPropertyCollection properties)
 		{
-			SettingsPropertyValueCollection pv = new SettingsPropertyValueCollection ();
-			foreach (SettingsProperty prop in properties)
-				pv.Add (new SettingsPropertyValue (prop));
-			return pv;
-			// FIXME: enable this when the compiler issue is solved.
-			//return impl.GetPropertyValues (context, properties);
+			return impl.GetPropertyValues (context, properties);
 		}
 
 #if CONFIGURATION_DEP
@@ -76,8 +71,6 @@ namespace System.Configuration
 			if (values != null)
 				impl.ApplicationName = values ["applicationName"];
 
-			// FIXME: this must be enabled
-			//impl.Initialize (name, values);
 			base.Initialize (name, values);
 		}
 #endif

+ 1 - 1
mcs/class/System/System.Configuration/SettingValueElement.cs

@@ -90,7 +90,7 @@ namespace System.Configuration
 
 		protected override void Reset (ConfigurationElement parentElement)
 		{
-			throw new NotImplementedException ();
+			node = null;
 		}
 
 		protected override void ResetModified ()