Improved error messages so that it becomes clear where configuration errors come...
[mono.git] / mcs / class / System.Configuration / System.Configuration.Provider / ProviderBase.cs
index fc9afe183c4365e5bb13148faffd9a7ef882d678..66c423c6fbb4262e308f022372b4f046b4e1c281 100644 (file)
@@ -36,16 +36,29 @@ namespace System.Configuration.Provider
 {
        public abstract class ProviderBase
        {
+               bool alreadyInitialized;
+               
                protected ProviderBase ()
                {
                }
                
                public virtual void Initialize (string name, NameValueCollection config)
                {
+                       if (name == null)
+                               throw new ArgumentNullException ("name");
+                       if (name.Length == 0)
+                               throw new ArgumentException ("Provider name cannot be null or empty.", "name");
+                       if (alreadyInitialized)
+                               throw new InvalidOperationException ("This provider instance has already been initialized.");
+                       alreadyInitialized = true;
+                       
                        _name = name;
 
-                       _description = config["description"];
-                       if (_description == null)
+                       if (config != null) {
+                               _description = config ["description"];
+                               config.Remove ("description");
+                       }
+                       if (String.IsNullOrEmpty (_description))
                                _description = _name;
                }