如何访问C#编译器? [英] How to access the C# compiler?

查看:77
本文介绍了如何访问C#编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I would like to know, if i want to add another check to my code during run-time, beside the regular code check, what do i need to do? for example counting how many times I've got the letter 'a' in my code. or how many times i have a variable containing the letter 'a'.
i'm assuming that the compiler does that part, so do i need to inherit from the compiler classes in order to get access to the words in my code? or does it have to do with visual studio?
i'm sort of stuck and have to give in a school project very soon i would be very happy if anyone can help me!





我尝试了什么:



i试图学习c#的编译器类并且没有太多运气。 ..



What I have tried:

i tried to learn the classes of the compiler of c# and didn't have much luck...

推荐答案



有几种方法可以做到这一点,我将简短列出最知名的方法:

1-使用
Hi,
There are several ways of doing this, I will short listed the most well know ones:
1- Use
System.CodeDom.Compiler

这将使您几乎可以访问C#编译器包含的所有内容。例如,您可以在运行时调用解析器并询问您感兴趣的查询。

2-您可以使用bath文件和pre-post构建事件来允许您运行每次构建之前和之后的一些批处理文件。在此处了解更多信息

3-您可以制作自己的C#编译器,但我不建议,但如果您对它感兴趣,那么请继续从官方链接下载源代码,例如 C#编译器单声道

4-解决方案1和2的组合,这也是一个好主意。



我希望这可以帮助你解决问题,如果没有请不要犹豫发表评论然后我可以改进这个解决方案,直到你的问题得到解决如果我无法提供帮助,或者道歉。祝你好运。



干杯,

AH

this will give you access almost to everything that C# compiler contains. For example, you can call the parser at run-time and ask for a query that you are interested in it.
2- You can use bath files and pre-post build events which allows you to run some batch files before and after each build. Read more in here
3- You can make your own C# compiler which I do not advice but if you are interested in it then just go ahead and download the source code from the official links such as C# Compiler Mono
4- Combination of solution 1 and 2 which is also a nice idea.

I hope this will help you to solve your problem if not please do not hesitate to leave a comment then I can improve this solution until your problem got solved or apologize if I was not able to be of help. Good luck.

Cheers,
AH


这篇关于如何访问C#编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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