密封类和对象浏览器
在对象浏览器窗口中检查 .net 对象模型时,我发现缺少有关密封类的信息。
例如,如果导航到 mscorlib 容器 -> 系统命名空间 -> String 类,详细信息窗格将显示以下内容:
公共类字符串
系统成员摘要:
将文本表示为一系列 Unicode 字符。属性:
[System.Runtime.InteropServices.ComVisibleAttribute(true), System.Reflection.DefaultMemberAttribute("Chars")]
看来我只能通过代码定义窗口或者尝试从它派生来确定类是否被密封。
然而,在关注 Andrew Troelsen 的 Apress - Pro C# 2008 和 .Net 3.5 Platform
时,作者在第 188 页上展示了对象浏览器如何显示密封状态:
此信息是否已从 Visual Studio 2008 对象浏览器中删除?我能以某种方式取回它吗?
虽然作者在整个文本中提到了 Visual Studio 2008,但该屏幕截图必须来自以前的版本。这本书实际上是第 4 版,早在 2001 年就推出了 .Net 1.0 Beta 2。
While inspecting the the .net object model in the Object Browser window, I came across the lack of information on sealed classes.
If for instance, one navigates to the mscorlib container -> System namespace -> String class, the details pane displays the following:
public class String
Member of SystemSummary:
Represents text as a series of Unicode characters.Attributes:
[System.Runtime.InteropServices.ComVisibleAttribute(true),
System.Reflection.DefaultMemberAttribute("Chars")]
It seems I can only ascertain if a class is sealed either through the Code Definition Window or, of course, by trying to derive from it.
Yet, while following Apress - Pro C# 2008 and the .Net 3.5 Platform
, by Andrew Troelsen, the author shows on page 188 how the object browser display the sealed status:
Has this information been removed from Visual Studio 2008 object browser? Could I get it back somehow?
Although the author mentions Visual Studio 2008 throughout the text, that screenshot must be from a previous version. The book is in fact in its 4th Edition, and started back in 2001 with .Net 1.0 Beta 2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道已经过去几年了,但我只是想确认我可以在 VS2k8 SP1 中看到这一点,但仅对于
String
。我认为这是因为
String
是唯一被标记为“特殊”(也许是原始类型?)的class
以及Integer
、< code>Long 等,它们都是ValueTypes
(结构
)。请注意问题中的图像中的
SByte
、Single
和String
在 LHS 树视图中不具有相同的图标就像他们现在所做的那样。编辑:又过了几年,我刚刚注意到 VS2k8 SP1 中的 VB.NET 确实说
Public NotInheritable Class String
我将“对象浏览器浏览”选择设置为“我的项目”或“所有组件”*,但当我选择特定的 .NET Framework 时,只有Public Class String
(并且属性已列出,但它们不在其他浏览选择)。*正如OP中捕获的显示一样!
注意:仅当您在 LHS 树视图上关闭
String
并再次打开它时,它才会更新显示。 VS2010 SP1 的行为相同。在 VS2010 中,我看到所有组件将
String
显示为NotInheritable
(对于 .NET 4)以及“空白”(对于 .NET 2 和 Silverlight),但我不能目前正在确认VS2008在类似情况下的显示情况。I know it's been a couple of years, but I'd just like to confirm I can see this in VS2k8 SP1, but only for
String
.I think it is because
String
is the onlyclass
that has been marked as "special" (primitive type perhaps?) along withInteger
,Long
, etc, which are allValueTypes
(structures
).Note in the image in the question
SByte
,Single
andString
do not have the same icon in the LHS treeview where as they do now.Edit: It's been another couple of years and I've just noticed for VB.NET in VS2k8 SP1 it does say
Public NotInheritable Class String
when I have the Object Browser Browse selection set to My Project or All Components*, but onlyPublic Class String
when I select a specific .NET Framework (and yet Attributes are listed, whereas they're not in the other Browse selections).*As in the display captured in the OP!
NB It only updates the display if you shift off
String
and back on it again on the LHS treeview. And VS2010 SP1 behaves identically.In VS2010 I see All Components showing
String
as bothNotInheritable
, for .NET 4, and "blank" for .NET 2 and Silverlight, but I can't currently confirm what VS2008 shows in a similar situation.我的Visual Studio 2008似乎没有这个问题。你升级到SP1了吗?您是否有其他工具或插件可以修改对象浏览器的功能?
My Visual Studio 2008 does not seem to have this issue. Are you upgraded to SP1? Do you have other tools or add-ins that modify the Object Browser's functionality?