运行时/实时处理用户键入命令.如何? [英] Runtime/Realtime process a user keyin command. How?

查看:61
本文介绍了运行时/实时处理用户键入命令.如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



创建一个文本框,用户可以在其中键入C#命令/代码.例如"For Loop"和一些动作语法.

用户按下确定"按钮后,软件/应用程序将处理代码并执行某些操作.

有人有任何线索吗?该怎么做?

谢谢.

#Update:
哦,我懂了.我还没有说清楚我的问题. em ..是的,适用于Windows应用程序.

非常感谢您的建议和解答.这些给了我一个线索.我会研究的.再次感谢

Hi,

Create a Textbox, user can keyin C# commands/codes within. for example, the "For Loop" and some action syntax.

after the user press the "OK" button, the software/application will process the code and perform some action.

Anyone has any clue? How to do this?

Thanks.

#Update:
Oh, I see. I haven''t make my question clear. em.. yes, its for windows Application.

and many thanks again for your advices and answers. These have gave me a clue on it. and I''ll study it. thanks again

推荐答案

这是您在说什么:用户将在文本框中键入一些代码,您的应用程序将运行它?
这可以使用CodeDomCSharpCodeProvider类来完成.看看这些课程,然后尝试一下.您将需要手动将Main函数包装在输入周围,以便对其进行编译.也看一下代码片段编译器.可能会有帮助.
Is this what you are saying: User will type some code in the textbox and your application will run it?

This can be done using CodeDom and CSharpCodeProvider classes. Have a look at these classes and give a try. You will need to manually wrap Main function around the input for it to compile. Take a look at snippet compiler as well. Might help.


绝对.我在这里提供了详细的答案:
使用CodeDom生成代码 [创建使用可重载插件的WPF应用程序... [ ^ ].

我有时会建议您的方法(感谢您提出的问题)而不是发明一种语言.
请参阅我的答案以及此讨论:
创建使用可重载插件的WPF应用程序... [ ^ ].

简短说明:它不称为实时".实时是完全不同的东西.这个术语有几个含义.但是我明白你的意思.这是个好主意,谢谢您提出有趣的问题.

祝你好运.
—SA
Absolutely. I provided detailed Answers here:
code generating using CodeDom[^].

Some more detail here:
Create WPF Application that uses Reloadable Plugins...[^].

I sometime suggest your approach (I appreciate your Question) instead of inventing a language.
Please see my Answer and also this discussion:
Create WPF Application that uses Reloadable Plugins...[^].

A short note: It is not called "real time". Real time is something completely different; there are several meaning of this term. But I understand what you mean. This is a good idea, thank you for the interesting Question.

Good luck.
—SA


此处有一篇文章对此进行了解释: ^ ]

它可能不完全是您想要的,但是它将为您提供想法.

[edit]

警告:如果在网站上实施此操作,则会在服务器中留下非常大的安全漏洞.请记住,代码将在服务器上运行,.NET可以访问所需的任何内容.如果用户输入的代码与删除c:\ *.*"的C#等效,则服务器将尝试执行此操作...

[/edit]
There is an article explaining this here: Compiling .NET code on-the-fly[^]

It may not be exactly what you want, but it will give you the idea.

[edit]

A word of warning: If you implement this in a website, you leave a VERY big security hole in your server. Remember that the code will be run on the server, and .NET has access to anything it needs. If the code the user enters is the C# equivalent of "Delete c:\*.*" then the server will try to do it...

[/edit]


这篇关于运行时/实时处理用户键入命令.如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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