Using Class Designer & OTB to better understand the .NET Framework
For those of you who don't know, Class Designer (CD) is a Visual Studio 2005 feature that lets you visually design/model your data types. You can use CD to design custom .NET classes and it can be also used to better understand and navigate an existing code base. One of the lesser known features of Class Designer is that you can also use it on .NET Framework types.
Let's say I wanted to create a Windows Form control, and I want to understand the object model for the Control class. Using Visual Studio 2005 Beta 1, simply create a new Windows Form application, right click on Solution Explorer and select "Add New Item...Class Diagram" . You'll now have a blank Class Diagram which you can drag and drop classes onto. To drag and drop classes, you'll need to switch to the Class View, "View...Class View" . This lists all the types in your project. In our case we want to understand .NET Framework types (which are in our project references) so we'll need to make one minor tweak to the Class View - make sure that the "Show Project References" checkbox is checked as shown below:
Next, Expand the project references folder and navigate to the DLL and namespace you are looking for as shown below:
Finally drag and drop the types you are interested in directly onto the class diagram. This picture shows the object hierarchy, interfaces and types for the Control class.
But wait there's more! If you saw my previous post on Object Test Bench (OTB), you can see how they can be used in concert and we can experiment with .NET Framework types using CD & OTB.
Aside: Frans Bouma asked a good question about being able to type code, rather then go through dialogs, and the good news is that you can also use the immediate window with OTB to create and call instances of classes.
Back to learning about the .NET Framework. For simplicity sake, let's say you want to learn about the design of the String class and maybe you want to test how the String.Compare() method works. To do this, we'll drag and drop System.String onto the Class Designer. You'll visually see its interfaces, fields, properties, and methods.
Now that we've added it onto our diagram, we can use OTB to call the String.Compare static method and choose the overload that accepts two string arguments as shown below:
When we select the Compare(string, string) method, we see a dialog box prompting us to enter the two string parameters, and we'll enter "Hello" and "World" as shown below:
When we click OK, Visual Studio will call the method and we get anotehr dialog box that shows that String.Compare returns "-1" when comparing the strings "hello" and "world."
Given that I think a lot of people will be using Class Designer to understand code, I'd love to see CDadd support for Namespaces. My goal would be that I could drag and drop a namespace and get a nice diagram of all the types within the namespace, and it would make it easy for anyone to create their own .NET Framework class diagram Poster for a specific namespace.
Comments
- Anonymous
January 27, 2005
I've used both tools and did not even notice the "Show Project References" option. Very slick! - Anonymous
February 01, 2005
Hi Dan,
Great post! A couple of things.
You can indeed drag and drop a namespace on the class diagram and visualize all the types in that namespace. In fact, in Beta2, we have really improved our auto layout algorithm that you will get a nicely laid out diagram for all the types in the namespace. Please see my blog entry (http://blogs.msdn.com/r.ramesh/archive/2005/01/18/355658.aspx).
With regard to referencing types from assemblies, if you have a field or a property whose type is, say string, you can right click on the property and select the Show as Association command and that will display the String class in the diagram. Similarly if your class derives from System.Windows.Forms.Form, then you can invoke the Show Base Class command to view that class.
Cheers,
Ramesh. - Anonymous
February 06, 2005
You mentioned this as a feature of Visual Studio--I've heard rumors that this feature is a C# only feature. I've also heard rumors that the refactoring tool will only be availabe in C#. Can you clarify that?
Thanks - Anonymous
February 09, 2005
Hey Chris,
Sorry for taking so long to respond, but I forwarded this to the VB team and they said that Object Test Bench would be available in Visual Basic. As far as refactoring goes, Visual Basic will include support for the Rename refactoring but won't include all of the refactoring features that C# will. You can read more about VB support for refactoring at: http://www.panopticoncentral.net/archive/2004/11/02/1934.aspx
Thanks,
-Dan - Anonymous
February 11, 2005
Thanks so much for getting back to me! - Anonymous
May 02, 2005
I find the ClassDiagram View a bit hard to navigate. Typical navigation controls, like middle mouse button pressed for pan and mouse wheel for zoom help a lot when navigating graphical views. Have I missed something and this is possible already? - Anonymous
May 06, 2005
John Stallo from the Class Designer sent me this email about the previous question on mouse support. Class Designer will support the following:
1. Zoom in/out: Ctrl + mouse-wheel.
2. Scroll up/down: Mouse-wheel.
3. Scroll left/right: Shift + Mouse-wheel
Thanks,
-Dan - Anonymous
March 22, 2006
Hi Dan,
The Create Instance option doesn't seem to appear with the Beta 3.Any idea...
Cheers
Chander - Anonymous
May 07, 2006
Draw Magic has been designed so you can create flowcharts, data-flow diagrams, process control charts and organizational charts with an exceptional ease.
http://www.yaodownload.com/video-design/miscellaneous/antechinus-draw-magic_miscellaneous.htm