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

Home Posts Topics Members FAQ

getting object array of method parameters

Given a method lik

public byte[] ReadFile(string filename,int offset, int bufferSize, bool eof

can I get an object array of the parameters which will work with any method without explicitly creating it mysel

in this case equivalent t

object[] ps = new object[]{filename,offset,bufferSize,eof}

Stev
Nov 16 '05 #1
10 3297
You can through Reflection:

class myClass
{
publiic void method1(string imp1)
{

}
}
.....

Tyope t = typeof(myClass);
MemberInfo mi = t.GetMethod("method1", BindingFlags.Instance);
ParameterInfo[] pi = mi.GetParameters();
From here on you have full access to the params of the method.

Cheers,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA, MCT
eAgility LLC
"Steve" <an*******@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
Given a method like

public byte[] ReadFile(string filename,int offset, int bufferSize, bool eof)
can I get an object array of the parameters which will work with any method without explicitly creating it myself
in this case equivalent to

object[] ps = new object[]{filename,offset,bufferSize,eof};

Steve

Nov 16 '05 #2
You can through Reflection:

class myClass
{
publiic void method1(string imp1)
{

}
}
.....

Tyope t = typeof(myClass);
MemberInfo mi = t.GetMethod("method1", BindingFlags.Instance);
ParameterInfo[] pi = mi.GetParameters();
From here on you have full access to the params of the method.

Cheers,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA, MCT
eAgility LLC
"Steve" <an*******@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
Given a method like

public byte[] ReadFile(string filename,int offset, int bufferSize, bool eof)
can I get an object array of the parameters which will work with any method without explicitly creating it myself
in this case equivalent to

object[] ps = new object[]{filename,offset,bufferSize,eof};

Steve

Nov 16 '05 #3
Branimir Giurov <br******@nospam.com> wrote:
You can through Reflection:

class myClass
{
publiic void method1(string imp1)
{

}
}
....

Tyope t = typeof(myClass);
MemberInfo mi = t.GetMethod("method1", BindingFlags.Instance);
ParameterInfo[] pi = mi.GetParameters();

From here on you have full access to the params of the method.


You know their types and names, but you *don't* have access to their
values, which is what the OP was after, I believe.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
That's correct, I've already looked into reflaction and GetParamters() doesn't actually get the values!

Steve
Nov 16 '05 #5
Steve <an*******@discussions.microsoft.com> wrote:
That's correct, I've already looked into reflaction and
GetParamters() doesn't actually get the values!


No. There's no way it could, really. Basically I don't believe there's
any way of doing what you want it to.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Branimir Giurov <br******@nospam.com> wrote:
You can through Reflection:

class myClass
{
publiic void method1(string imp1)
{

}
}
....

Tyope t = typeof(myClass);
MemberInfo mi = t.GetMethod("method1", BindingFlags.Instance);
ParameterInfo[] pi = mi.GetParameters();

From here on you have full access to the params of the method.


You know their types and names, but you *don't* have access to their
values, which is what the OP was after, I believe.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
That's correct, I've already looked into reflaction and GetParamters() doesn't actually get the values!

Steve
Nov 16 '05 #8
Steve <an*******@discussions.microsoft.com> wrote:
That's correct, I've already looked into reflaction and
GetParamters() doesn't actually get the values!


No. There's no way it could, really. Basically I don't believe there's
any way of doing what you want it to.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #9
On Tue, 6 Apr 2004 11:53:11 +0100, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
Steve <an*******@discussions.microsoft.com> wrote:
That's correct, I've already looked into reflaction and
GetParamters() doesn't actually get the values!


No. There's no way it could, really. Basically I don't believe there's
any way of doing what you want it to.


Using Context Bound Objects is one way to access full method call
information. Context bound objects allways execute in their own
appdomain and use the remoting services to communicate.

The astute developer can inject his own ChannelSink into the remoting
channel and intercept the actual IMessage for the method call, gaining
access to all the parameters and their values.

Nov 16 '05 #10
On Tue, 6 Apr 2004 11:53:11 +0100, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
Steve <an*******@discussions.microsoft.com> wrote:
That's correct, I've already looked into reflaction and
GetParamters() doesn't actually get the values!


No. There's no way it could, really. Basically I don't believe there's
any way of doing what you want it to.


Using Context Bound Objects is one way to access full method call
information. Context bound objects allways execute in their own
appdomain and use the remoting services to communicate.

The astute developer can inject his own ChannelSink into the remoting
channel and intercept the actual IMessage for the method call, gaining
access to all the parameters and their values.

Nov 16 '05 #11

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

Similar topics

6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
5
by: Steve | last post by:
Given a method lik public byte ReadFile(string filename,int offset, int bufferSize, bool eof can I get an object array of the parameters which will work with any method without explicitly...
2
by: Jeff Van Epps | last post by:
We've been unable to get events working going from C# to VJ++. We think that the C# component is being exposed properly as a ConnectionPoint, and the Advise() from the VJ++ side seems to be...
14
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...
1
by: Darsin | last post by:
Hi all, I am a new programmer to C# and i am having a following problem. I want to make a single method which takes a variable length array and display it contents. i have defined the method as:...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
7
by: Aaron Gray | last post by:
I put together the following code to get the href's parameters :- function GetParameters() { var arg = new Object(); var href = document.location.href; if ( href.indexOf( "?") != -1) { var...
5
by: Eric bouxirot | last post by:
hi, i'd like to do a "cast", who seem to be very complicated in .NET. in C standard it's so easy... i explain : i have made an app based on plugin architecture in VB.NET. all work fine.. ...
7
by: Steve | last post by:
I am building an object library for tables in a database. What is the best practice for creating objects like this? For example, say I have the following tables in my database: User: - Id -...
7
by: Andrus | last post by:
How to get syntactically correct signature which compiles for code template grneration ? I tried code below but it creates syntactically incorrect signature. Andrus. using System; using...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
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
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
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.