Sealed classes and Object Browser

雨燕双飞 提交于 2019-12-11 06:59:14

问题


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 System

Summary:
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.


回答1:


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 only class that has been marked as "special" (primitive type perhaps?) along with Integer, Long, etc, which are all ValueTypes (structures).

Note in the image in the question SByte, Single and String 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 only Public 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 both NotInheritable, for .NET 4, and "blank" for .NET 2 and Silverlight, but I can't currently confirm what VS2008 shows in a similar situation.




回答2:


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?



来源:https://stackoverflow.com/questions/1694791/sealed-classes-and-object-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!