Reputation: 2020
apologies if this a naive question. I have written a "universal" C# Web service client: it works by examining the WSDL of any Web service, and generating a Windows Forms UI that allows you to submit requests to the Web service and display responses.
It generates the UI as follows: first, it dynamically generates a compiled assembly (using ServiceDescriptionImporter and CodeCompiler) from the Web service's WSDL, and then it introspects on the SoapHttpClientProtocol client generated by this process.
For each Web service method, the UI to display the input parameter fields is generated by reflecting on the parameter types. Essentially, I have to recognize each type and decide how best to display it (so a String parameter is displayed as a textbox, a Boolean as a checkbox, and so on).
The types I'm having difficulty recognizing are types such as ArrayOfKeyValuestringstringKeyValueOfstringstring. I could simply parse the name of types ( along the lines of if (name begins with "ArrayOf")), but I'm sure there must be a better way to recognize these types as being arrays in some way.
If anyone can suggest how to do this, I'd be most grateful! Thanks, Martin
Upvotes: 1
Views: 196
Reputation: 2020
Unfortunately, this does not work either because I need to programmatically extract the types of keys and values. For other, technical, reasons, I have upgraded my client to use the .Net 4.0 WsdlImporter and its related classes which generates more clearly typed code, and as a by-product avoids the use of these ArrayOf classes. Thanks for your help!
Upvotes: 0
Reputation: 2841
If it's any type of array or list, it will implement IEnumerable, so this may get you off in the right direction:
if (typeof(IEnumerable).IsAssignableFrom(typeof(ArrayOfKeyValuestringstringKeyValueOfstringstring)))
{
// ok, it's an array...
}
EDIT: Martin (user304582) points out that some other types like String implement IEnumerable. My assumption here is that, at this point in the code, the simple types (like String, Int32, etc) have already been tested for - and it is not one of them.
One could also use Array
instead of IEnumerable
, assuming ServiceDescriptionImporter generates parameters using arrays and not lists in all cases.
Upvotes: 1