Resharper 智能感知混乱
今天,我的 Resharper 5 副本中发生了一些奇怪的事情。我有一个如下所示的类:
public class Foo
{
public string Username { get; private set; }
public Foo (string userName) { Username = userName; }
public void Bar()
{
DoWork(Username);
}
public void DoWork(string userName) { }
}
当我开始输入 DoWork(us 时,我从 intellisense 中得到以下内容:
请注意,它正在提取构造函数参数,并以冒号结尾: userName:
这里发生了什么?
编辑:
正如 Reed 在下面回答的那样,这是一个新的 C# 4 功能,名为 命名参数和可选参数。它的目的是允许您指定参数的名称,而不是它在参数列表中的位置。因此您不必记住参数列表中参数的位置即可使用它(尽管这对于智能感知来说基本上没有意义)。不过,它确实使可选参数更易于使用。
谢谢里德。
Today I had something weird happen in my copy of Resharper 5. I have a class that looks like this:
public class Foo
{
public string Username { get; private set; }
public Foo (string userName) { Username = userName; }
public void Bar()
{
DoWork(Username);
}
public void DoWork(string userName) { }
}
When I start to type DoWork(us I get the following from intellisense:
Notice that it's pulling up the constructor argument, and it ends with a colon: userName:
What's going on here?
EDIT:
As Reed answered below, this is a new C# 4 feature called Named and Optional Arguments. It's purpose is to allow you to specify the name of an argument, rather than it's position in a parameter list. so you don't have to remember the position of an argument in the argument list to use it (though this is largely meaningless with intellisense). It does make optional arguments easier to use though.
Thanks Reed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 Resharper,为命名参数和可选参数提供智能感知支持。
C# 4 添加了对这些的支持。现在,您可以定义如下方法:
如果您想使用不同的“用户名”调用此方法,但保留其他参数的默认值,您可以执行以下操作:
Resharper 5 在智能感知中添加了对此语法的支持。
This is Resharper providing intellisense support for Named and Optional Arugments.
C# 4 added support for these. You can now have a method defined like this:
If you want to call this with a different "userName" but leave the default for other parameters, you can do:
Resharper 5 adds support for this syntax in intellisense.
您没有包括 ;在用户名的末尾
You didn't include the ; at the end of userName