Author: mhabersack
Date: 2007-05-15 04:07:45 -0400 (Tue, 15 May 2007)
New Revision: 77394

Modified:
   trunk/mcs/class/System.Configuration/System.Configuration/ChangeLog
   
trunk/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs
Log:
2007-05-15  Marek Habersack  <[EMAIL PROTECTED]>

        * ConfigurationElement.cs: added value validation on
        deserialization from the config file.



Modified: trunk/mcs/class/System.Configuration/System.Configuration/ChangeLog
===================================================================
--- trunk/mcs/class/System.Configuration/System.Configuration/ChangeLog 
2007-05-15 07:46:59 UTC (rev 77393)
+++ trunk/mcs/class/System.Configuration/System.Configuration/ChangeLog 
2007-05-15 08:07:45 UTC (rev 77394)
@@ -1,3 +1,8 @@
+2007-05-15  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * ConfigurationElement.cs: added value validation on
+       deserialization from the config file.
+
 2007-05-14 Igor Zelmanovich <[EMAIL PROTECTED]>
 
        * ConfigurationElement.cs: when attribute value cannot be parsed,

Modified: 
trunk/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs
===================================================================
--- 
trunk/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs
   2007-05-15 07:46:59 UTC (rev 77393)
+++ 
trunk/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs
   2007-05-15 08:07:45 UTC (rev 77394)
@@ -310,11 +310,17 @@
                                
                                if (readProps.ContainsKey (prop))
                                        throw new ConfigurationException ("The 
attribute '" + prop.Name + "' may only appear once in this element.");
-                               
+
+                               string value = null;
                                try {
-                                       prop.SetStringValue (reader.Value);
-                               }
-                               catch (Exception ex) {
+                                       value = reader.Value;
+                                       ValidateValue (prop.Property, value);
+                                       prop.SetStringValue (value);
+                               } catch (ConfigurationErrorsException) {
+                                       throw;
+                               } catch (ConfigurationException) {
+                                       throw;
+                               } catch (Exception ex) {
                                        string msg = String.Format ("The value 
of the property '{0}' cannot be parsed.", prop.Name);
                                        throw new ConfigurationErrorsException 
(msg, reader);
                                }
@@ -324,9 +330,7 @@
                        reader.MoveToElement ();
                        if (reader.IsEmptyElement) {
                                reader.Skip ();
-                       }
-                       else {
-
+                       } else {
                                int depth = reader.Depth;
 
                                reader.ReadStartElement ();
@@ -538,6 +542,18 @@
                        PropertyInformation info = 
ElementInformation.Properties [propName];
                        return info != null && info.ValueOrigin == 
PropertyValueOrigin.SetHere;
                }
+
+               void ValidateValue (ConfigurationProperty p, string value)
+               {
+                       ConfigurationValidatorBase validator;
+                       if (p == null || (validator = p.Validator) == null)
+                               return;
+                       
+                       if (!validator.CanValidate (p.Type))
+                               throw new ConfigurationException (
+                                       String.Format ("Validator does not 
support type {0}", p.Type));
+                       validator.Validate (p.ConvertFromString (value));
+               }
        }
        
        internal class ElementMap

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to