用用户定义的名称创建一个新方法.反射C# [英] create a new method with a user-defined name. Reflection C#

查看:69
本文介绍了用用户定义的名称创建一个新方法.反射C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想在运行时上创建一个方法.
我希望用户输入一个字符串,该方法的名称将为DynamicallyDefonedMethod_####(以用户字符串结尾).

我希望将相同的字符串嵌入方法的主体中:
它将调用StaticallyDefinedMethod (####, a, b)

像这样的东西:

Hello,

I want to create a method on RunTime.
I want the user to enter a string and the method''s name will be DynamicallyDefonedMethod_#### (ends with the user string).

i want the same string to be embeded in the method''s body:
It will call StaticallyDefinedMethod (####, a, b)

Something like:

public MyClass1 DynamicallyDefonedMethod_#### (int a, int b)
{
return  StaticallyDefinedMethod (####, a, b)
}



这样的想法是,用户将在运行时创建一个新方法,然后再调用它(带有a,b参数).

我用C#反射进行了搜索,但发现没有简便的方法.有人知道该怎么做吗?


是否可以定义新方法[webmethod]?
问候,



The idea is that the user will create a new method on runtime and invoke it afterward (with a, b parameters).

I googled C# reflection but found no easy way of doing that. Does someone knows how to do it simply ?


Is it possible to define that new method [webmethod] ?
Regards,

推荐答案

无论您想对这些东西做什么,都不是一件容易的事.您需要大量学习.

有关介绍,请首先参见以下内容: http://msdn.microsoft.com/en-us/library/sfk2s47t .aspx [^ ] ,然后查看他的类型描述和代码示例: http://msdn. microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.aspx [
振作起来!

—SA
Whatever you want to do with that stuff, it is not very easy. You''ll need to leans a good deal.

For introduction, see this first: http://msdn.microsoft.com/en-us/library/sfk2s47t.aspx[^], then look at his type description and the code sample: http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.aspx[^].

If you say you already saw this and still did not get the answer (remembering you phrase "I Googled C# reflection but found no easy way of doing that"), you probably have to simply slow down and stop your search: you already found what you need, now it''s time to read and work it through. If you try to find anything easier than that, you will only waste time.

Cheer up!

—SA


这篇关于用用户定义的名称创建一个新方法.反射C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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