在c#win中突出显示所选功能。形成 [英] Highlighting the selected function in c# win. form

查看:53
本文介绍了在c#win中突出显示所选功能。形成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我正在研究代码审核者项目,但我面临的问题是,只要点击活动的内容,事件就会突出显示,我可以自己做突出显示的代码但是如何确定事件的起始位置和结束位置





示例

recently i am working on a code reviewer project but the problem i am facing is that as soon as i click the event's content the event should get highlighted, i can do the highlighted code myself but how to identify where the event is starting and where it is ending.


Example

//private void button1_Click
private void button1_Click(object sender, EventArgs e)
{
     //My Cursor lies here
}



例如:上面是我的代码,请记住不应删除注释。现在我如何得到活动的开始和结束,因为我的重点在于功能的中间。





在此先感谢


for example: above is my code keeping in mind the comment should not be removed. now how do i get the event start and end as my focus lies in the middle of the function.


Thanks in advance

推荐答案

总结问题我需要一个算法,从当前焦点所在的文本框中获取事件/函数的开始和结束。



这不是一件小事:你需要处理整个文件的语法。



你甚至不能只是从当前位置倒退,直到你到达公共,私人,受保护或内部这个词,因为:

1)它可能是在一串注释中,你不知道直到你到达字符串或注释的开头。

2)它可能不存在:C#允许你默认访问修饰符。

3)如果语法错误怎么办?你要走多远了?

4)如果你在enum,构造函数,嵌入式类,属性,字段,lambda或者......中怎么办?



除非你处理整个文件的语法,否则你不会知道你在哪里。并且没有算法:它基本上是编写新C#编译器的前几个阶段......
"to sum the question up i need an algorithm that gets the start and end of the event/function from textbox where my current focus lies."

That is not trivial: you need to process the syntax of the whole file.

You can't even just "run backwards" from the current location until you reach the word "public", "private", "protected", or "internal" because:
1) It could be in a string of comment, and you don't know until you get to the start of the string or comment.
2) It might not be there: C# allows you to "default" the access modifier.
3) What if there is a syntax error? How far back do you go?
4) What if you are in an enum, or a constructor, or an embedded class, or a property, or a field, or a lambda, or...

Unless you process the syntax of the whole file you don't "know" where you are. And there is no algorithm for that: it's basically the first couple of stages of writing a new C# compiler...


这篇关于在c#win中突出显示所选功能。形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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