Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
microsoft.public.dotnet.framework.sdk
Reflection-based Invokation with "out" Parameters
Brian Vargas
10/8/2002 8:21:00 PM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Greetings,
I am attempting to invoke a method via reflection. Normally this isn't
a problem, but the catch is that one of the parameters of the method I
am calling is an "out" parameter.
I am pretty sure that I can make all of this work by manually
enumerating the methods on my object using GetMethods() and then
searching for a method that matches my expected signature using the
ParameterInfo objects returned by the GetParameters() method off the
MethodInfo object.
What I want to know is: Is there a better way? Ideally, I'd like to
simply call the GetMethod() method off the Type object, but it does not
seem to support searching by modified parameter. There is one that
takes an array of ParameterModifier structs, but that structure doesn't
seem to be documented very well.
Any thoughts?
Brian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6-2 (MingW32)
Comment: Using GnuPG with Mozilla -
http://enigmail....
iEYEARECAAYFAj2jIjYACgkQ3YdPnMKx1eOvKACcDPo22ey4Rw/12L1dmjIPD9i6
d7UAn0XUwMhI/aqBAAtEqRmtIqNxLVZO
=X8tx
-----END PGP SIGNATURE-----
1 Answer
Manish Godse [MS]
10/8/2002 10:39:00 PM
0
You should be able to treat out parameters as ref parameters and call
GetMethod. Try something like this:
using System;
using System.Reflection;
public class M{
public void Method(out int x){
x = 200;
Console.WriteLine("Called out Method");
}
public static void Main(){
Type t = typeof(M);
M m = (M)Activator.CreateInstance(t); // Create an
instance of M
Type [] p = new Type[1];
p[0] = Type.GetType("System.Int32&"); // typeof(ref int) out
is really ref with an extra custom attribute
MethodInfo mi = t.GetMethod("Method", p); // Get the method
Object [] ps = new Object[1]; // Create param
array
mi.Invoke(m, ps); // Call the method
Console.WriteLine(ps[0]);
}
}
--
Hope this helps,
Manish Godse
Microsoft
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.
This posting is provided \"AS IS\" with no warranties, and confers no
rights.
"Brian Vargas" <noreply@ardvaark.net> wrote in message
news:#kbyjdvbCHA.1688@tkmsftngp09...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Greetings,
>
> I am attempting to invoke a method via reflection. Normally this isn't
> a problem, but the catch is that one of the parameters of the method I
> am calling is an "out" parameter.
>
> I am pretty sure that I can make all of this work by manually
> enumerating the methods on my object using GetMethods() and then
> searching for a method that matches my expected signature using the
> ParameterInfo objects returned by the GetParameters() method off the
> MethodInfo object.
>
> What I want to know is: Is there a better way? Ideally, I'd like to
> simply call the GetMethod() method off the Type object, but it does not
> seem to support searching by modified parameter. There is one that
> takes an array of ParameterModifier structs, but that structure doesn't
> seem to be documented very well.
>
> Any thoughts?
>
> Brian
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6-2 (MingW32)
> Comment: Using GnuPG with Mozilla -
http://enigmail....
>
> iEYEARECAAYFAj2jIjYACgkQ3YdPnMKx1eOvKACcDPo22ey4Rw/12L1dmjIPD9i6
> d7UAn0XUwMhI/aqBAAtEqRmtIqNxLVZO
> =X8tx
> -----END PGP SIGNATURE-----
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Reflection-based Invokation with "out" Parameters
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password