diff options
author | Chris Toshok <toshok@novell.com> | 2005-11-09 22:13:03 +0300 |
---|---|---|
committer | Chris Toshok <toshok@novell.com> | 2005-11-09 22:13:03 +0300 |
commit | e2359b782979ca70861579d16cdc2d2dbad2e76e (patch) | |
tree | a9c6880aad08cbb970b6705601b275c075679db5 /mcs/class/System.Configuration | |
parent | b490269c01ab3fa09d1d211760af02cd0c23e1dd (diff) |
2005-11-09 Chris Toshok <toshok@ximian.com>
* ConfigurationElement.cs: Add support for DefaultCollection
attributes.
* PropertyInformation.cs (PropertyInformation.Value): add case for
IsDefaultCollection.
* SectionGroupInfo.cs (SectionGroupInfo.ReadConfig): when we read
a "type" attribute, make sure the cached System.Type is cleared.
svn path=/trunk/mcs/; revision=52793
Diffstat (limited to 'mcs/class/System.Configuration')
4 files changed, 76 insertions, 6 deletions
diff --git a/mcs/class/System.Configuration/System.Configuration/ChangeLog b/mcs/class/System.Configuration/System.Configuration/ChangeLog index d5e0eeb95c4..42cd50f8275 100644 --- a/mcs/class/System.Configuration/System.Configuration/ChangeLog +++ b/mcs/class/System.Configuration/System.Configuration/ChangeLog @@ -1,3 +1,14 @@ +2005-11-09 Chris Toshok <toshok@ximian.com> + + * ConfigurationElement.cs: Add support for DefaultCollection + attributes. + + * PropertyInformation.cs (PropertyInformation.Value): add case for + IsDefaultCollection. + + * SectionGroupInfo.cs (SectionGroupInfo.ReadConfig): when we read + a "type" attribute, make sure the cached System.Type is cleared. + 2005-10-25 Chris Toshok <toshok@ximian.com> * InfiniteTimeSpanConverter.cs: new implementation. diff --git a/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs b/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs index 6bed780cce9..fdcc11fac30 100644 --- a/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs +++ b/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs @@ -42,6 +42,7 @@ namespace System.Configuration bool modified; ElementMap map; ConfigurationPropertyCollection keyProps; + ConfigurationElementCollection defaultCollection; bool readOnly; ElementInformation elementInfo; ConfigurationElementProperty elementProperty; @@ -147,7 +148,7 @@ namespace System.Configuration { if (keyProps != null) return keyProps; - if (map.Properties == Properties) + if (map != null && map.Properties == Properties) keyProps = map.KeyProperties; else { keyProps = new ConfigurationPropertyCollection (); @@ -159,6 +160,31 @@ namespace System.Configuration return keyProps; } + internal ConfigurationElementCollection GetDefaultCollection () + { + if (defaultCollection != null) return defaultCollection; + + ConfigurationProperty defaultCollectionProp = null; + + if (map != null && map.Properties == Properties) { + defaultCollectionProp = map.DefaultCollectionProperty; + } + else { + foreach (ConfigurationProperty prop in Properties) { + if (prop.IsDefaultCollection) { + defaultCollectionProp = prop; + break; + } + } + } + + if (defaultCollectionProp != null) { + defaultCollection = this [defaultCollectionProp] as ConfigurationElementCollection; + } + + return defaultCollection; + } + protected internal object this [ConfigurationProperty property] { get { return this [property.Name]; } set { this [property.Name] = value; } @@ -169,7 +195,7 @@ namespace System.Configuration PropertyInformation pi = ElementInformation.Properties [property_name]; if (pi == null) throw new InvalidOperationException ("Property '" + property_name + "' not found in configuration element"); - + return pi.Value; } @@ -258,8 +284,15 @@ namespace System.Configuration PropertyInformation prop = ElementInformation.Properties [reader.LocalName]; if (prop == null || (serializeCollectionKey && !prop.IsKey)) { - if (!OnDeserializeUnrecognizedElement (reader.LocalName, reader)) + if (prop == null) { + ConfigurationElementCollection c = GetDefaultCollection (); + if (c != null && c.OnDeserializeUnrecognizedElement (reader.LocalName, reader)) + continue; + } + + if (!OnDeserializeUnrecognizedElement (reader.LocalName, reader)) { throw new ConfigurationException ("Unrecognized element '" + reader.LocalName + "'."); + } continue; } @@ -450,7 +483,8 @@ namespace System.Configuration ConfigurationPropertyCollection properties; ConfigurationPropertyCollection keyProperties; - + ConfigurationProperty defaultCollectionProperty; + ConfigurationCollectionAttribute collectionAttribute; public static ElementMap GetMap (Type t) @@ -536,6 +570,19 @@ namespace System.Configuration public ConfigurationCollectionAttribute CollectionAttribute { get { return collectionAttribute; } } + + public ConfigurationProperty DefaultCollectionProperty { + get { + if (defaultCollectionProperty == null) { + if (properties != null) + foreach (ConfigurationProperty p in properties) { + if (p.IsDefaultCollection) defaultCollectionProperty = p; + break; + } + } + return defaultCollectionProperty; + } + } } } diff --git a/mcs/class/System.Configuration/System.Configuration/PropertyInformation.cs b/mcs/class/System.Configuration/System.Configuration/PropertyInformation.cs index 3b5c20ad504..a91e4a60d7e 100644 --- a/mcs/class/System.Configuration/System.Configuration/PropertyInformation.cs +++ b/mcs/class/System.Configuration/System.Configuration/PropertyInformation.cs @@ -114,8 +114,18 @@ namespace System.Configuration elem.SetReadOnly (); val = elem; origin = PropertyValueOrigin.Inherited; - } else + } + else if (property.IsDefaultCollection) { + ConfigurationElementCollection col = (ConfigurationElementCollection) Activator.CreateInstance (Type); + col.InitFromProperty (this); + if (owner != null && owner.IsReadOnly ()) + col.SetReadOnly (); + val = col; + origin = PropertyValueOrigin.Inherited; + } + else { return DefaultValue; + } } return val; } diff --git a/mcs/class/System.Configuration/System.Configuration/SectionGroupInfo.cs b/mcs/class/System.Configuration/System.Configuration/SectionGroupInfo.cs index bc711b7f231..0e8a512f97d 100644 --- a/mcs/class/System.Configuration/System.Configuration/SectionGroupInfo.cs +++ b/mcs/class/System.Configuration/System.Configuration/SectionGroupInfo.cs @@ -146,8 +146,10 @@ namespace System.Configuration while (reader.MoveToNextAttribute ()) { if (reader.Name == "name") Name = reader.Value; - else if (reader.Name == "type") + else if (reader.Name == "type") { TypeName = reader.Value; + Type = null; + } else ThrowException ("Unrecognized attribute", reader); } |