Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2011-02-12 19:17:05 +0300
committerSebastien Pouliot <sebastien@ximian.com>2011-02-12 19:32:47 +0300
commit24f4a89224cb6db07581073ec3ad0bd57f2b9cb5 (patch)
treec0ed03bb3f9b093d9cade9bc0ff98cf7ac21877e
parent1d3b0a2ec5fc84bdbadf06576c9e589eb61a73c6 (diff)
Relax XSD to accept non-integer parameter values (e.g. double and strings)2.10
* Settings.cs: Allow settings configuration to reflect using double and string (in addition to integer) since some rules can use those types. * gendarme.xsd: Relax the parameter value to xs:string Fix bug #671178
-rw-r--r--gendarme/console/Settings.cs41
-rw-r--r--gendarme/console/gendarme.xsd2
2 files changed, 35 insertions, 8 deletions
diff --git a/gendarme/console/Settings.cs b/gendarme/console/Settings.cs
index a23b1b48..3ecafec7 100644
--- a/gendarme/console/Settings.cs
+++ b/gendarme/console/Settings.cs
@@ -188,22 +188,49 @@ namespace Gendarme {
foreach (XmlElement parameter in nodes.SelectNodes ("parameter")) {
string ruleName = GetAttribute (parameter, "rule", String.Empty);
string propertyName = GetAttribute (parameter, "property", String.Empty);
- int value;
- if (!Int32.TryParse (GetAttribute (parameter, "value", String.Empty), out value))
- value = 0;
IRule rule = GetRule (ruleName);
if (rule == null)
- throw new XmlException (String.Format ("The rule with name {0} doesn't exist. Review your configuration file.", ruleName));
+ throw GetException ("The rule with name {0} doesn't exist", ruleName, String.Empty, String.Empty);
PropertyInfo property = rule.GetType ().GetProperty (propertyName);
if (property == null)
- throw new XmlException (String.Format ("The property {0} can't be found in the rule {1}. Review your configuration file.", propertyName, ruleName));
+ throw GetException ("The property {1} can't be found in the rule {0}", ruleName, propertyName, String.Empty);
if (!property.CanWrite)
- throw new XmlException (String.Format ("The property {0} can't be written in the rule {1}. Review your configuration file", propertyName, ruleName));
- property.GetSetMethod ().Invoke (rule, new object[] {value});
+ throw GetException ("The property {1} can't be written in the rule {0}", ruleName, propertyName, String.Empty);
+
+ string value = GetAttribute (parameter, "value", String.Empty);
+ if (String.IsNullOrEmpty (value))
+ continue;
+
+ object [] values = new object [1];
+ switch (Type.GetTypeCode (property.PropertyType)) {
+ case TypeCode.Int32:
+ int i;
+ if (Int32.TryParse (value, out i))
+ values [0] = i;
+ break;
+ case TypeCode.Double:
+ double d;
+ if (Double.TryParse (value, out d))
+ values [0] = d;
+ break;
+ case TypeCode.String:
+ values [0] = value;
+ break;
+ }
+
+ if (values [0] == null)
+ throw GetException ("The value '{2}' could not be converted into the property {1} type for rule {0}", ruleName, propertyName, value);
+
+ property.GetSetMethod ().Invoke (rule, values);
}
}
+ static Exception GetException (string message, string ruleName, string propertyName, string value)
+ {
+ return new XmlException (String.Format (message + ". Review your configuration file.", ruleName, propertyName, value));
+ }
+
public bool Load ()
{
ValidateXmlDocument ();
diff --git a/gendarme/console/gendarme.xsd b/gendarme/console/gendarme.xsd
index 86e29a47..d38767b4 100644
--- a/gendarme/console/gendarme.xsd
+++ b/gendarme/console/gendarme.xsd
@@ -34,7 +34,7 @@
<xs:complexType name="parameterType">
<xs:attribute name="rule" type="notEmptyString" use="required"/>
<xs:attribute name="property" type="notEmptyString" use="required"/>
- <xs:attribute name="value" type="xs:integer" use="required"/>
+ <xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>
<!-- Facets -->