It hit me I can use Reflexion... So
webbservice.Results result;
//Loop through each of the node in XMLResults
foreach(XmlNode childNode in XMLResults) {
string element = childNode.Name;
//use reflexion to get the name and the value of the result
object from the DHI web service
Type type = typeof(webservice.Result);
PropertyInfo p = type.GetProperty(element);
if(p != null) {
//check to see if the value of the result object matches
the value of the child node
if((string)p.GetValue(result, null) !=
childNode.InnerText) {
//Add to my error list
} //if p.Value
} //if p
}
On Aug 13, 5:00 pm, Scott <[email protected]> wrote:
> I am writing a program to run test scenarios against a web service.
> The test scenarios are contained in an XML document. I need to check
> the returned value of the web service against a node in the XML
> document.
>
> If the result of the web service were un-typed I could use a single
> line of code to solve my problem:
>
> if (webServiceResult[element].ToString() == node.InnerText)
>
> HOWEVER, the web service result variable is strongly typed and I would
> need to write a switch statement for every element in the web service.
>
> Since I'm lazy, how can I convert the strongly-typed web service
> result object into an un-typed object I can reference using string
> variables?