getting object array of method parameters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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 said:
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
 
Branimir Giurov said:
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.
 
That's correct, I've already looked into reflaction and GetParamters() doesn't actually get the values!

Steve
 
Steve said:
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.
 
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.
 
Back
Top