如何只为特定的 class 实例化而不是代码的其他部分替换参数名称?

How to replace argument name only for a particular class instantiation and not in other parts of code?

我在 Visual Studio 2017 年使用 C#(也有 ReSharper 9)并遇到以下问题:

我像这样实例化了很多 classes:

new SystemMessage(SystemMessageType.Error, _internalId, "Request Failed: RequestAvailableScripts", e)

我的目标是将参数名称 internalId 替换为 entityId。我无法执行全局 find/replace 因为 internalId 也出现在其他地方。我只想替换 new SystemMessage(....) 的构造函数中的参数名称。我不熟悉正则表达式,也无法理解如何处理构造函数的第一个参数,SystemMessageType.Error 因为 Error 只是枚举 SystemMessageType. I want to replace the argument name_internalId 的一个可能值within **all**new SystemMessage(....)` 无论第一个参数如何,都传递到 class 构造函数中。

编辑:为了更清楚,class 的构造函数中的第一个、第三个和第四个参数不同,所以无论我想替换第二个参数名称,但只在这个特定的 class 构造函数不在代码的其他部分。

试试这个正则表达式:

(new SystemMessage\([^)]*?)(_internalId)

替换为:

entityId

Click for Demo