C#函数就像PHP中的eval()一样? [英] C# function like eval() in PHP?

查看:78
本文介绍了C#函数就像PHP中的eval()一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建动态对象并使用动态对象名称调用函数。

有人可以帮我找到答案吗?



< b>我尝试了什么:



没有尝试过。

i want to create dynamic objects and call function with dynamic object name.
can anybody help me to find answer?

What I have tried:

Nothing tried.

推荐答案

没有。没有办法直接这样做,因为C#是一种编译语言(不像PHP那样被解释)并且需要在执行ti之前编译所有代码。

话虽如此,你可以这样做:在运行时编译C#代码 [ ^ ]显示了一种方式,但您可能需要封装 你的代码在某种框架中让它全部运转起来。一个简单的谷歌会找到你的其他人:编译并执行c - Google搜索 [ ^ ]



但是...我想很长在我开始之前很难:你正在把你的应用程序的所有控制权交给那些想要将一些代码捆绑在一起并让你执行它的内部工作。从安全POV来看,这是一场噩梦 - 从可靠性的角度来看,我可以看到很多错误报告都是由用户代码引起的而不是你的。
No. There is no way to do that directly, as C# is a compiled language (unlike PHP which is interpreted) and requires all code to be compiled before ti is executed.
Having said that, you could do it: Compiling C# Code at Runtime[^] shows one way, but you would probably have to "encapsulate" your code in some kind of framework to get it all to work. A simple Google will find you others: compile and execute c - Google Search[^]

But...I'd think long and hard before I started with this: you are handing all control of your app and it's inner workings to whoever wants to bash together some code and get you to execute it. From a security POV, that's a nightmare - and from a reliability standpoint I could see a lot of bug reports coming that are caused by "user code" rather than yours.


这篇关于C#函数就像PHP中的eval()一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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