473,480 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

MethodInfo.Invoke and reading ref parameters

ian
Hi,

I can't find a solution to this, so I've brought it to the experts.
Using reflection I can get a MethodInfo object pointing at an assembly's
method.
Where I have a MethodInfo object pointing at a function, say func(int
p1, ref int p2), how do I read p2 after a successful invocation?
I've tried interogating the parameterinfo objects on the method, I've
seen some hints about overriding something or casting some other object
type to an array of objects, but no concrete examples, not even some
sand ones!

Thank you

*** Sent via Developersdex http://www.developersdex.com ***
Jun 23 '06 #1
1 12663
ian <no****@devdex.com> wrote:
I can't find a solution to this, so I've brought it to the experts.
Using reflection I can get a MethodInfo object pointing at an assembly's
method.
Where I have a MethodInfo object pointing at a function, say func(int
p1, ref int p2), how do I read p2 after a successful invocation?
The object array you pass to Invoke() gets modified, and the value
returned is put in the correct location in the array.
I've tried interogating the parameterinfo objects on the method, I've
seen some hints about overriding something or casting some other object
type to an array of objects, but no concrete examples, not even some
sand ones!


---8<---
using System;
using System.Reflection;

class App
{
static void Main()
{
MethodInfo doubleInt = typeof(App).GetMethod("DoubleInt",
BindingFlags.NonPublic | BindingFlags.Static);
object[] args = { 21 };
doubleInt.Invoke(null, args);
Console.WriteLine(args[0]);
}

static void DoubleInt(ref int x)
{
x = x * 2;
}
}
--->8---

-- Barry

--
http://barrkel.blogspot.com/
Jun 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
7325
by: stic | last post by:
Hi, I'm in a middle of writing something like 'exception handler wraper' for a set of different methodes. The case is that I have ca. 40 methods form web servicem, with different return values...
0
391
by: Ffelagund | last post by:
Hello I'm trying to load dinamically some dll's but when I try to invoke one method, I ever get ArgumentException if I'm not using native types. Here are the .h of the dll: #pragma once...
1
2182
by: Sivaraman.S | last post by:
Hi, Can i pass integer array to methodInfo.Invoke(obj,args()). I am able to pass only string array to this function. This is the code i have written. Dim myType As Type = objClass.GetType()...
3
9528
by: Me | last post by:
I am trying to figure out any issues with calling System.Reflection.MethodInfo.Invoke() when dealing with multiple threads. For instance.. Say I have a class that allows you to pass in a...
2
12242
by: Phill W. | last post by:
For some time, I've been adding "trace level" logging to my code using Imports System.Reflection Private Function XYZ( a1 as A, b1 as B, c1 as C, ... TRACE.Log(...
2
3016
by: John Lutz | last post by:
Our app is mainly COM based. We allow .NET plug-ins. When a plug-in is installed, it receives a COM pointer to the app. The plug-in implements our IExtensionImpl interface and gets the app...
3
3402
by: Lambuz | last post by:
Hi all, when I use MethosInfo.Invoke method I obtain a TargetInvocationException where inner exception is +{"classBase.OpenConn cannot be invoked directly" } System.Exception. I'm using the...
15
8170
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
11
23603
by: KMinFL | last post by:
This is a C# VS 2008 question... Our system has 2 base classes, SingleEntity and NewPluralEntity. SingleEntity provides access to properties and methods related to manipulating data in a database...
0
7032
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4767
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.