找到所有可选参数并将其删除
在一些类中到处使用了可选参数后,我开始非常不喜欢它们,因为它们在某些情况下会导致重载解析的麻烦,即由于签名冲突以及动态调用问题而难以将委托绑定到它们关于方法参数计数。
如何搜索 Visual Studio IDE (2010) 项目中的所有文件并找到所有可选参数用法?也许我可以使用一个聪明的正则表达式?或者可能使用不支持可选参数的旧版本 Visual Studio?我试图避免手动扫描项目中文件的麻烦,因为它可能很烦人且容易出错。谢谢!
Having used optional parameters in a few classes here and there, I'm starting to dislike them immensely for the trouble they cause in certain cases with overload resolution, i.e. difficulties in binding delegates to them due to signature conflicts, as well as dynamic invocation problems with regard to method argument count.
How can I search in all files in my Visual Studio IDE (2010) project and locate all optional parameter usage? Would there be a clever regex I could use perhaps? Or perhaps using an older version of Visual Studio where optional parameters are not supported? I'm trying to avoid the hassle of manually scanning files in the project as it can be tiresome and error-prone. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您最好的选择可能是反射 - 它应该很容易循环遍历所有类型的所有成员,其中它们是方法并且它们至少有一个可选参数。
这不会代替您,但可以为您提供所有违规成员的列表。
像这样的东西:
Your best bet may be reflection - it should be easy enough to loop through all members of all types where they are methods and they have at least one optional parameter.
That wouldn't do the substitution for you, but could give you a list of all offending members.
Something like:
虽然这可能不是我在 Visual Studio 中查看类视图的最佳方式。方括号中显示的类型是可选参数
Whilst this isn't probably the best way I tend to look at the Class View in visual studio. The types that are shown in square brackets are the optional parameters