简体   繁体   English

是否有可能找到每次分配给特定变量的情况?

[英]Is it possible to find every occurrence of a particular variable being assigned to?

I am aware using 'Find all references' I can find every 'mention' of a variable - but is it possible to refine this search by only showing code that assigns a value to the variable in question? 我知道使用“查找所有引用”可以找到变量的每个“提法”,但是是否可以通过仅显示为问题变量分配值的代码来优化此搜索?

For example: 例如:

var test = 1;
var test2 = test + 3;
test = 123;

Find all references with 'test' as the criteria would show all 3 lines. 查找所有带有“测试”的参考,因为标准将显示所有3行。

The search I am after would show me only lines 1 and 3. 我进行的搜索只会显示第1行和第3行。

How about test\\s*=\\s*.*; test\\s*=\\s*.*;怎么样test\\s*=\\s*.*; ? Use the find feature in the IDE and make sure regular expression is checked. 在IDE中使用查找功能,并确保选中正则表达式

This will search for test followed by any amount of white space followed by = followed by any amount of white space followed by anything followed by ; 这将搜索test其后跟任意数量的空格,后跟=,再跟任意数量的空格,后跟任何东西,然后是;

It will fail on multiline stuff though; 但是,它将在多行内容上失败; eg 例如

test = \
123;

and the rather flashy trigraph sequence : 和相当华而不实的三部曲序列

test = ??/
123;

although I'm not certain C# has either of these constructs. 尽管我不确定C#具有这两种构造。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM