C#接受参数&在运行时从文本文件声明 [英] C# taking arguments & declaring at runtime from text file

查看:67
本文介绍了C#接受参数&在运行时从文本文件声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下各行的文本文件

I have a text file containing following lines

int A = 5 ;
string str = "tempstring" ;
str DosomeMethod 15 16 20 22 ;


通过程序读取文本文件行时,我想声明int A = 5&来自运行时的字符串str ="tempstring".

就像


When reading text file lines thru program I wanted to declare int A = 5 & string str = "tempstring" from runtime.

It cane be like

string[] st = freader.readline().split(' ');
if (st[0]=="int")
    {
      str[0] str[1] = str[4];
    }


我知道上面是奇怪的语法,但是我的意思是要用一些引用来做到这一点.


I know that above is wrond syntax but I mean to do like this with some ref. Can anybody help without using irony .net?

推荐答案

您实际上需要代码解释器或内置脚本语言吗?您可能会发现几种基于不同语言的库,但是使用c#很简单,不是吗?好了,框架已经有了.请参阅: http://msdn.microsoft.com/en-us/library/microsoft. csharp.csharpcodeprovider.aspx [ ^ ].

您可以找到一些基于此功能的工具,可以从以下工具开始​​:
运行时C#表达式评估器 [在运行时编译代码 [
You actually want a code interpreter, or a built-in scripting language. You will probably find several libraries based on different languages, but it is straightforward to use c#, isn''t it? Well, the framework has it already. See: http://msdn.microsoft.com/en-us/library/microsoft.csharp.csharpcodeprovider.aspx[^].

You can find several tools based on this feature, you can start with these ones:
Runtime C# Expression Evaluator[^]
Compiling code during runtime[^]

Note, that .net 4 introduced some new features.


这篇关于C#接受参数&在运行时从文本文件声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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