473,388 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 3296
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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...

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.