Author: atsushi
Date: 2007-05-30 13:46:17 -0400 (Wed, 30 May 2007)
New Revision: 78240
Modified:
trunk/mcs/class/System/System.Configuration/ApplicationSettingsBase.cs
trunk/mcs/class/System/System.Configuration/ChangeLog
trunk/mcs/class/System/System.Configuration/ConfigXmlDocument.cs
trunk/mcs/class/System/System.Configuration/LocalFileSettingsProvider.cs
trunk/mcs/class/System/System.Configuration/SettingsBase.cs
trunk/mcs/class/System/System.Configuration/SettingsProviderCollection.cs
Log:
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.
Modified: trunk/mcs/class/System/System.Configuration/ApplicationSettingsBase.cs
===================================================================
--- trunk/mcs/class/System/System.Configuration/ApplicationSettingsBase.cs
2007-05-30 17:42:32 UTC (rev 78239)
+++ trunk/mcs/class/System/System.Configuration/ApplicationSettingsBase.cs
2007-05-30 17:46:17 UTC (rev 78240)
@@ -250,86 +250,90 @@
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;
+ if (setting_attrs == null ||
setting_attrs.Length == 0)
+ continue;
+ CreateSettingsProperty (prop,
properties, ref local_provider);
+ }
+ }
- 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);
- }
- }
+ return properties;
+ }
+ }
- SettingsProperty
setting = new SettingsProperty (prop.Name,
-
prop.PropertyType,
-
provider,
-
false /* XXX */,
-
defaultValue /* XXX always a string? */,
-
serializeAs,
-
dict,
-
false, false);
+ 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);
+ }
+ }
- if (providerService !=
null)
-
setting.Provider = providerService.GetSettingsProvider (setting);
+ SettingsProperty setting =
+ new SettingsProperty (prop.Name,
prop.PropertyType, provider, false /* XXX */,
+ defaultValue /* XXX
always a string? */, serializeAs, dict,
+ false, false);
- 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;
- }
+ if (providerService != null)
+ setting.Provider =
providerService.GetSettingsProvider (setting);
- properties.Add
(setting);
-
- if (setting.Provider !=
null && Providers [setting.Provider.Name] == null)
- Providers.Add
(setting.Provider);
- }
- }
+ 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;
+ }
- return properties;
+ 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
Modified: trunk/mcs/class/System/System.Configuration/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Configuration/ChangeLog 2007-05-30
17:42:32 UTC (rev 78239)
+++ trunk/mcs/class/System/System.Configuration/ChangeLog 2007-05-30
17:46:17 UTC (rev 78240)
@@ -1,5 +1,16 @@
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
property is accessed. It should not use virtual providers,
properties or context internally since they could be overriden.
Modified: trunk/mcs/class/System/System.Configuration/ConfigXmlDocument.cs
===================================================================
--- trunk/mcs/class/System/System.Configuration/ConfigXmlDocument.cs
2007-05-30 17:42:32 UTC (rev 78239)
+++ trunk/mcs/class/System/System.Configuration/ConfigXmlDocument.cs
2007-05-30 17:46:17 UTC (rev 78240)
@@ -117,6 +117,16 @@
}
}
+#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
//
Modified:
trunk/mcs/class/System/System.Configuration/LocalFileSettingsProvider.cs
===================================================================
--- trunk/mcs/class/System/System.Configuration/LocalFileSettingsProvider.cs
2007-05-30 17:42:32 UTC (rev 78239)
+++ trunk/mcs/class/System/System.Configuration/LocalFileSettingsProvider.cs
2007-05-30 17:46:17 UTC (rev 78240)
@@ -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
Modified: trunk/mcs/class/System/System.Configuration/SettingsBase.cs
===================================================================
--- trunk/mcs/class/System/System.Configuration/SettingsBase.cs 2007-05-30
17:42:32 UTC (rev 78239)
+++ trunk/mcs/class/System/System.Configuration/SettingsBase.cs 2007-05-30
17:46:17 UTC (rev 78240)
@@ -52,6 +52,15 @@
public virtual void Save ()
{
+ if (sync)
+ lock (this)
+ SaveCore ();
+ else
+ SaveCore ();
+ }
+
+ void SaveCore ()
+ {
//
// Copied from ApplicationSettingsBase
//
Modified:
trunk/mcs/class/System/System.Configuration/SettingsProviderCollection.cs
===================================================================
--- trunk/mcs/class/System/System.Configuration/SettingsProviderCollection.cs
2007-05-30 17:42:32 UTC (rev 78239)
+++ trunk/mcs/class/System/System.Configuration/SettingsProviderCollection.cs
2007-05-30 17:46:17 UTC (rev 78240)
@@ -40,25 +40,24 @@
: 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 ];
}
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches