开发者

Parsing C# code to evaluate expressions (basically, implementing Intellisense)

开发者 https://www.devze.com 2022-12-27 13:54 出处:网络
I\'m trying to evaluate C# code as it gets typed, think of it as if I\'m trying to write an IDE. So a person types code, I want to find out what code did he just write:

I'm trying to evaluate C# code as it gets typed, think of it as if I'm trying to write an IDE.

So a person types code, I want to find out what code did he just write:

String x = "";

I want to now register that x is a type of String. And now everytime the user types x again, and I want to show him all the things he can do with x, basically like Visual Studio Intellisense.

Will I need some lexers or parsers for this? Will that make it easie开发者_JS百科r? I've heard VS 2010 has some features around this that Microsoft has released. Any ideas?


You can use the DLR to help with this. See DLRPad on codeplex for an example

If you use the DLR interrogate types in the CLR more easy than using reflection in C#. last time I looked (about 9 months ago) I thought the intellisense had been implemented using this technique as we were going to do it the same way.


I would avoid trying to write this yourself if you can. SharpDevelop is an open source .NET IDE which has Intellisense-like functionality. I believe you can embed their editor in your own project. According to Wikipedia, the license is LGPL so you could probably use it even in closed source projects. Of course, you should verify this for yourself before doing so.

Actipro SyntaxEditor is a third party control you can buy which does this. There are WinForms and WPF versions of the control. It has worked well for us. It doesn't currently support Intellisense with LINQ and lambda expressions. I don't know if SharpDevelop supports this or not.


I don't think .NET 4 has anything to help with this. You might look at Mono REPL. It also might help if you give more details about what you actually want to do.

0

精彩评论

暂无评论...
验证码 换一张
取 消