471,337 Members | 810 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Convert.ChangeType with reference type ie Int32& - can I get the base type?

I am trying to invoke a web service method dynamically. I have created
a generic function that takes a method name, string of parameters and
calls the web method using System.Reflection:

MethodInfo mi = proxyInstance.GetType().GetMethod(methodName);
object[] paramsArray = (object[])methodParams.ToArray(typeof(object));
object result = mi.Invoke(proxyInstance, paramsArray);

where methodParams is an array of parameters where the value stripped
from the string has been converted into the relevant system.type using:
methodParams[i] = Convert.ChangeType(methodParams[i],

This works fine unless the web method uses reference parameters.
Reference parameters themselves are not a problem if I didn't have to
use the Convert.ChangeType function. Convert.ChangeType does not work
with type System.Int32&.

Ref strings are fine because I can just avoid using the function
altogether but is there a way I can get the base type of a ByRef
parameter? I had a look at the structure of ParameterType but couldn't
find anywhere where System.Int32& could be interpreted as System.Int32

I can use this:
if (pi[i].ParameterType == System.Type.GetType("System.Int32&"))
paramValue = Convert.ChangeType(paramValue,
System.Type.GetType("System.Int32") );

but this requires me to code for each specific ref type. Is there a
simple property that allows me to get the right type?


Jul 21 '05 #1
1 5345
>but this requires me to code for each specific ref type. Is there a
simple property that allows me to get the right type?



Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Christoph Boget | last post: by
14 posts views Thread by Chris | last post: by
2 posts views Thread by jiangyh | last post: by
9 posts views Thread by Andy Sutorius | last post: by
3 posts views Thread by Scott M. | last post: by
9 posts views Thread by Edward Diener | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.