简体   繁体   English

为什么VS 2008不在Intellisense中为String类显示扩展方法

[英]Why doesn't VS 2008 display extension methods in Intellisense for String class

Since String implements IEnumerable<char> , I was expecting to see the Enumerable extension methods in Intellisense, for example, when typing the period in 由于String实现了IEnumerable<char> ,因此我希望在Intellisense中看到Enumerable扩展方法,例如,在输入句点时

String s = "asdf";
s.

I was expecting to see .Select<char>(...) , .ToList<char>() , etc. I was then suprised to see that the extension methods do in fact work on the string class, they just don't show up in Intellisense. 我期待看到.Select<char>(...) .ToList<char>()等等。我当时惊讶地看到,扩展方法在String类的工作其实这样做 ,他们只是不出现在Intellisense中。 Does anyone know why this is? 有人知道为什么吗? This may be related to this question. 这可能与这个问题有关。

It's by explicit design. 这是通过明确的设计。 The problem is that while String most definitely implements IEnumerable<T> , most people don't think of it, or more importantly use it, in that way. 问题是虽然String绝对实现了IEnumerable<T> ,但大多数人都没有想到它,或者更重要的是以这种方式使用它。

String has a fairly small number of methods. String只有很少的方法。 Initially we did not filter extension methods off of String and the result was a lot of negative feedback. 最初我们没有过滤String的扩展方法,结果是很多负面反馈。 It almost tripled the number of methods at times with the right imports. 使用正确的导入,它有时几乎使方法数量增加了两倍。 With all of the extension methods displayed, people often couldn't see the String method they were looking for in the noise. 显示所有扩展方法后,人们常常看不到他们在噪声中寻找的String方法。

String is a ... simple type and it's better to view it that way :) 字符串是......简单类型,最好以这种方式查看:)

It's still completely possible to call an extension method on string. 完全可以在字符串上调用扩展方法。 It's just likely not going to show up in intellisense. 它很可能不会出现在intellisense中。

EDIT: String actually has quite a few methods. 编辑:字符串实际上有很多方法。 But because many of them are overloads they collapse in intellisense. 但由于它们中的许多都是超载,它们在智能感知中崩溃了。

For info, this has changed in VS2010 (in beta 2, at least). 有关信息,这在VS2010中已经发生了变化(至少在beta 2中)。 It looks like this filtering has been removed (presumably it caused too much confusion), and the methods are now visible, along with the extension-method glyph. 看起来这个过滤已被删除(可能是它引起了太多混乱),现在这些方法与扩展方法字形一起可见。

It should. 这应该。

For example you can write it public static string myExtensionMethod(this String yuppi){
}

Then it is supposed to be there. 那应该是在那里。

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

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