获取方法参数的对象数组 [英] getting object array of method parameters

查看:61
本文介绍了获取方法参数的对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个方法如下
public byte [] ReadFile(string filename,int offset,int bufferSize,bool eof


我可以吗得到一个参数的对象数组,它将适用于任何方法而无需显式创建它mysel


在这种情况下相当于t


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


Stev

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

推荐答案

你可以通过反思:


class myClass

{

publiic void method1(string imp1)

{$ $
}

}

.....


Tyope t = typeof(myClass);

MemberInfo mi = t.GetMethod(" method1",BindingFlags.Instance);

ParameterInfo [] pi = mi.GetParameters();

从这里你可以完全访问方法的参数。


干杯,

Branimir


-

Branimir Giurov

MCSD.NET,M CDBA,MCT

eAgility LLC

" Steve" <一个******* @ discussions.microsoft.com>在留言中写道

news:06 ********************************** @ microsof t.com ...
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...
给定一个方法,如

public byte [] ReadFile(string filename,int offset,int bufferSize,bool
eof)方法,而无需自己明确地创建它
在这种情况下相当于

对象[] ps =新对象[] {filename,offset,bufferSize,eof};

史蒂夫
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



你可以通过反思:


class myClass

{

publiic void method1(string imp1)

{


}

}

.....


Tyope t = typeof(myClass) ;

MemberInfo mi = t.GetMethod(" method1",BindingFlags.Instance);

ParameterInfo [] pi = mi.GetParameters();

从这里开始,您可以完全访问该方法的参数。


干杯,< br $>
Branimir


-

Branimir Giurov

MCSD.NET,MCDBA,MCT
eAgility LLC

" Steve" <一个******* @ discussions.microsoft.com>在留言中写道

news:06 ********************************** @ microsof t.com ...
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...
给定一个方法,如

public byte [] ReadFile(string filename,int offset,int bufferSize,bool
eof)方法,而无需自己明确地创建它
在这种情况下相当于

对象[] ps =新对象[] {filename,offset,bufferSize,eof};

Steve
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< br * *****@nospam.com>写道:
Branimir Giurov <br******@nospam.com> wrote:
你可以通过反思:

类myClass
{publiic void method1(string imp1)
{

}
}
....

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

从这里开始,您可以完全访问方法的参数。
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.




你知道他们的类型和名字,但是你没有*可以访问他们的

值,这是OP所追求的,我相信。 />

-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复该群组,请不要也寄给我



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


这篇关于获取方法参数的对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆