在方法中获取方法参数 [英] Getting method arguments inside a method
本文介绍了在方法中获取方法参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让方法体内的方法参数作为对象数组?
例如:
Is there a way to get method arguments inside a method body as an array of objects?
For example:
public void main()
{
dosomething(2, "a");
}
public void dosomething(int a, string b)
{
// get 2, "a" as object[] here
}
编辑:
一些ascii艺术来解释上下文。
Some ascii art to explain the context.
-------- --------
|client| --- serialize call --> |server|
-------- --------
dosomething(2,"a"); ---> dosomething(2,"a");
在客户端创建一个代理,它将方法名称和args发送到服务器并将其值返回给服务器客户。
Create a proxy on the client which will send the method name and args to the server and return it''s value to the client.
推荐答案
嗯,不完全一样,请参阅: http://kalpeshshirodker.wordpress.com/2007/08/06/functions-with-variable-parameters-in-c/ [ ^ ] http://stackoverflow.com/questions/2062883/is-有一种通过枚举传递的方法参数 [ ^ ] options。
Well, not exactly like that, see: http://kalpeshshirodker.wordpress.com/2007/08/06/functions-with-variable-parameters-in-c/[^] and this http://stackoverflow.com/questions/2062883/is-there-a-way-to-enumerate-passed-method-paramters[^] options.
你可以做
public void dosomething(params object [] args)
但我不会没有充分的理由。
You can do
public void dosomething(params object[] args)
but I wouldn''t without really good reason.
[OP'澄清后添加到问题中]
澄清后,问题开始类似于服务合同,因为它们在WFC中使用。我认为这可以成为一个很好的思考:
http://en.wikipedia .org / wiki / Service-oriented_architecture#Programmatic_service_contract [ ^ ],
http://msdn.microsoft.com /en-us/library/ms733070.aspx [ ^ ],
http://msdn.microsoft .com / zh-CN / library / ms734686.aspx [ ^ ],
http ://msdn.microsoft .com / zh-cn / library / system.servicemodel.servicecontractattribute.aspx [ ^ ]。
-SA
[After OP''s clarification added to the question]
After clarification, the problem started to resemble Service Contracts, as they are used in WFC. I think it can be a good food for thought:
http://en.wikipedia.org/wiki/Service-oriented_architecture#Programmatic_service_contract[^],
http://msdn.microsoft.com/en-us/library/ms733070.aspx[^],
http://msdn.microsoft.com/en-us/library/ms734686.aspx[^],
http://msdn.microsoft.com/en-us/library/system.servicemodel.servicecontractattribute.aspx[^].
—SA
这篇关于在方法中获取方法参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文