如何提取 ReSharper 模式中字符串的内容?
我遇到以下问题:
LINQ 成员表达式替换包含属性名称的硬编码字符串
// like this:
NotifyOfPropertyChange("MyProperty");
// becomes
NotifyOfPropertyChange(() => MyProperty);
我想用带有 ReSharper 模式的
。以下尝试不起作用:
NotifyOfPropertyChange("$prop$"); // ($prop$ is of type Identifier, results in parse error)
NotifyOfPropertyChange($prop$); // ($prop$ is of type Expression [System.String],
// almost works, but without removing the quotes
替换模式始终相同:
NotifyOfPropertyChange(() => $prop$);
有什么想法吗?
I've got the following problem:
I want to replace a hardcoded string which contains a property name with a LINQ member expression
// like this:
NotifyOfPropertyChange("MyProperty");
// becomes
NotifyOfPropertyChange(() => MyProperty);
with a ReSharper pattern.
The following attempts didn't work:
NotifyOfPropertyChange("$prop$"); // ($prop$ is of type Identifier, results in parse error)
NotifyOfPropertyChange($prop$); // ($prop$ is of type Expression [System.String],
// almost works, but without removing the quotes
The replace pattern was always the same:
NotifyOfPropertyChange(() => $prop$);
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不需要 R# 的结构搜索和替换(这很幸运,因为我认为在当前版本中它不能做到这一点)。 Visual Studio 的查找和替换正则表达式应该足够好:
( )
被转义,这样它们就不会成为分组结构;{ }
标记与其中的模式匹配,以使它们可用于替换表达式。这里的所有内容都是文字,除了
\1
之外,这意味着“第一个标记表达式”。I don't think you need R#'s Structural Search and Replace here (which is fortunate, because I don't think in the present version it can do this). Visual Studio's Find and Replace regexes should be good enough:
The
( )
are escaped so that they dontg become a grouping construct; the{ }
tag whatever matches the pattern within to make them available to the replace expressionEverything here is literal except
\1
, which means 'the first tagged expression'.如果我正确理解你的意图,那么这可能会有所帮助。
前段时间我发现了这段代码(不记得最初是谁发布的)
所以以下:
应该给出结果:
If I understand your intention correctly then this maybe will help.
Some time ago I found this piece of code ( can't remember who posted it originally)
So the following:
should give a result: