Click here to Skip to main content
Click here to Skip to main content

Mole II Black Ops - Multifunction Visual Studio Visualizer For WPF - View Public, Private and Protected Data

, , , 17 Dec 2007
Rate this:
Please Sign up or sign in to vote.
A high octane multifunction visualizer that allows detailed inspection of the visual tree and logical trees. New feature of Mole II Black Ops allows viewing and drilling into non-public members of any element or sub-element in the visual or logical trees.

Mole 2010 is Now Available

Mole2010.gif

If you are using Visual Studio 2010 and would like to use the Mole debugging tool, please visit http://www.molosoft.com to get your copy today. Mole 2010 makes debugging easier.

Mole for Visual Studio Released

All versions of Mole have been replaced by Mole For Visual Studio.

Please refer to this article Mole For Visual Studio.

This article is here for informational purposes. The downloads have been removed. Please download and use Mole For Visual Studio. Thank you!

Introduction

This is the third article in the Mole WPF Visual Studio Visualizer series. This article covers a new and exciting feature - Black Ops. Black Ops enables Mole to return non-public members of objects that are selected in the visual or logical trees. Additionally, non-public members can also be returned during a drilling operation.

Previous Mole Articles

This article focuses on the new features added to Mole II. If you have not read the below articles, please read them to fully understand Visual Studio Visualizers and Mole.

Read Mole v1 Code Project Article.

Read Mole II v2 Code Project Article.

Mole's Home Page and Manual

Read Mole's Manual and visit Mole's Home Page.

Mole's Email

Please send your comments and feedback to molefeedback@yahoo.com.

Team Mole

Mole was authored by Karl Shifflett, Josh Smith and Andrew Smith.

Karl wrote this article which is why "I" appears in the article and I make references to myself.

Background

I have been amazed at the response that Mole & Mole II have received. One such response came from a super developer and great guy from the Raleigh, NC area, Rob Zelt. He wrote this blog post on Mole II. In this posting, he wondered if Mole would work with Silverlight applications. I did the research and as of Silverlight 1.1, visualizers are not supported. I do not know if they will be in Silverlight 2.0 scheduled to be released Q1 2008.

If visualizers will not be supported in Silverlight 2.0, I have come up with two alternate methods to provide Silverlight developers Mole functionality and will write the program shortly after the release of Silverlight 2.0. I would welcome suggestions from Silverlight developers for this product. Please leave comments at the bottom of this article or on my blog.

During my investigation of Silverlight and Mole, many new ideas started to surface. One of them was viewing and drilling into private and protected members. Currently Mole views public objects and properties. So we can thank Rob Zelt for asking me this question which lead to this code being authored and Mole getting Black Ops capabilities.

Where did this Black Ops business come from? Well, I was going to call it, "Mole! Show me your privates!" (private members right). Actually Mole took a left turn and ended up on the set of 24 and hung around Jack Bauer too long. Just keeping it fun!

Black Ops is used in this article but in the program UI we have chosen to follow .NET nomenclature and call the private and protected members fields, since that is what is being displayed. Again, just keeping it fun. (Truth be told, Josh talked me out of it.) As you know, you can easily change anything about Mole with very little effort, colors, labels, displayed data, etc.

Mole Black Ops

Mole Black Ops

First off, two columns have been renamed. Property Name has been renamed to Name and Property Type has been renamed to Type. The reason for this is that the Black Ops items can now be properties or fields.

In the above image, a TabControl has been selected in the Visual Tree TreeView Control. The breadcrumb points this out. We can see the Favorites this user has set up and the values that are displayed. Below the Favorites section is the new Fields (Black Ops) section.

Fields (Black Ops) Section

  • Region is pinned (frozen like the Favorites section).
  • Region supports collapse/expand.
  • Field items may be assigned to the Favorites section. If assigned to Favorites that field will be displayed with the Favorites.
  • Field items have their Category Name set to ({field attribute} Field). {field attribute} is from the FieldInfo.Attributes that you can read about in this MSDN FieldInfo.Attributes article.
  • Field items are all non-public fields and non-public properties.
  • Field items support drilling like their public members do.
  • Google search has been disabled for all Field items since the search would return strange results.

Below the Search TextBox there is a new Show Fields CheckBox which allows the Fields section to not be displayed if desired. This setting is persisted between Mole sessions.

Black Ops Collapsed

Black Ops Collapsed

The Fields section has been collapsed.

Black Ops Data

Black Ops Data

Some would ask, why show Private or Protected members? Allow me to list two reasons.

In the above image, I have selected a String from the logical tree. Notice the members of the String Class. Mole Black Ops has revealed some internal information that I never knew about before I started drilling around using Black Ops. I spent about an hour just drilling around and checking out WPF's classes using this feature.

The real reason I wanted this feature was to be able to view Private and Protected members that I have defined in my own classes. Now when I'm using Mole, I can view and drill into the module level Private and Protected members of classes I have written. This provides a more in-depth view of my class data.

Private and Protected Data

For Each obj As System.Reflection.FieldInfo In _
  target.GetType.GetFields(BindingFlags.NonPublic Or _
    BindingFlags.Instance)

    Dim bolIsDepencencyProperty As Boolean = False

    'note the default value is set to null

    Dim strValue As String = STRING_NULL
    Dim strValueSource As String = String.Empty
    Dim bolIsDrillable As Boolean = False

    Try

        Dim objValue As Object = obj.GetValue(target)

        If objValue IsNot Nothing Then
            strValue = objValue.ToString
            bolIsDrillable = _
              IsDrillableTest(obj.ReflectedType, objValue)
        End If

    Catch ex As Exception
        'just ignoring the exception

    End Try

    objList.Add(New TreeElementProperty(bolIsDepencencyProperty, _
      bolIsDrillable, _
      String.Format(STRING_BLACK_OPS_INDICATOR_FORMAT, obj.Attributes.ToString), _
      obj.Name, obj.FieldType.Name, strValue, strValueSource))
Next

Viewing Private and Protected members of an object is really quite simple. It requires the use of .NET reflection. The Type.GetFields method returns a collection of FieldInfo objects. This method has an overload that allows the developer to specify what fields in the target object to return by passing the BindingFlags parameter. In the above code, I'm passing BindingFlags.NonPublic Or BindingFlags.Instance.

Because of the way Mole is designed, adding this feature was very simple. I inserted the above code at the end of the MoleVisualizerObjectSource.GetTreeElementProperties function.

The GetTreeElementProperties function exposes some of the internal workings of Mole. It is here that data displayed in the properties grid is checked if it is drillable or not.

You can also see that Mole is string based. Look at what the UI is passed in the above objList.Add call. A bunch of strings!

Since the UI for Mole and the data source for Mole are in two separate processes, the UI does not have any references to the data it displays. It is this utterly simplistic design that allows Mole to be easily extended. It is the responsibility of the Mole's data source to maintain references to objects that Mole is viewing so that those objects can be drilled into when the user desires.

Close

Unless there is a bug, this might be the last installment of Mole until the Silverlight version in Q1 2008. Karl needs to get back to work on a multi-player WPF game he has been working on. The game should be released in stores Q2 2008.

Hope this article can help someone learn a little more about Visual Studio Visualizers For WPF.

History

  • 11 December 2007: Initial release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Authors

Andrew Smith
Architect Infragistics, Inc.
United States United States
Andrew currently works as an architect for Infragistics working with windows forms and WPF. You can check out his blog here.

Josh Smith
Software Developer (Senior) Cynergy Systems
United States United States
Josh creates software, for iOS and Windows.
 
He works at Cynergy Systems as a Senior Experience Developer.
 
Read his iOS Programming for .NET Developers[^] book to learn how to write iPhone and iPad apps by leveraging your existing .NET skills.
 
Use his Master WPF[^] app on your iPhone to sharpen your WPF skills on the go.
 
Check out his Advanced MVVM[^] book.
 
Visit his WPF blog[^] or stop by his iOS blog[^].
Follow on   Twitter

Karl Shifflett
Architect Gayle Manufacturing Company
United States United States
Karl loves .NET, WPF, WCF, ASP.NET, VB.NET and C#.
 
Awards:
 
  • December 2008 VB.NET Code Project Article Award
  • 2009 Code Project MVP
  • 2008 Code Project MVP
  • 2008 Microsoft MVP - Client App Dev
  • December 2007 VB.NET Code Project Article Award
  • Gold Medal Winner at IBM's 1998 PROIV Programming Contest in Las Vegas
Click here to check out my Blog
 
Click here to learn about Mole 2010 debugging tool for Visual Studio 2010
 
Click here to read about XAML Power Toys
 

Just a grain of sand on the worlds beaches.

Follow on   Twitter

Comments and Discussions

 
GeneralSuggestion - Resource Visualizer PinmemberCyanide13-Dec-07 7:54 
GeneralRe: Suggestion - Resource Visualizer PinmemberKarl Shifflett13-Dec-07 16:48 
GeneralRe: Suggestion - Resource Visualizer PinmvpJosh Smith14-Dec-07 1:52 
GeneralRe: Suggestion - Resource Visualizer PinmemberCyanide14-Dec-07 3:31 
GeneralRe: Suggestion - Resource Visualizer PinmvpJosh Smith14-Dec-07 3:36 
General110, 767 KB PinmvpRama Krishna Vavilala11-Dec-07 6:58 
GeneralRe: 110, 767 KB PinmemberKarl Shifflett11-Dec-07 7:56 
GeneralRe: 110, 767 KB PinmemberKarl Shifflett11-Dec-07 8:00 
GeneralLove it, but... PinmemberKent Boogaart11-Dec-07 5:43 
GeneralRe: Love it, but... PinmvpJosh Smith11-Dec-07 5:50 
GeneralRe: Love it, but... PinmemberKarl Shifflett11-Dec-07 6:49 
GeneralRe: Love it, but... [modified] PinmemberKarl Shifflett11-Dec-07 11:01 
GeneralRe: Love it, but... PinmemberKent Boogaart11-Dec-07 22:48 
GeneralLovin' it! PinmvpJosh Smith11-Dec-07 3:57 
GeneralRe: Lovin' it! PinmemberKarl Shifflett11-Dec-07 4:37 
GeneralRe: Lovin' it! PinmvpJosh Smith11-Dec-07 4:40 
GeneralRe: Lovin' it! [modified] PinmemberKarl Shifflett11-Dec-07 4:54 
JokeRe: Lovin' it! PinmvpJosh Smith11-Dec-07 4:55 
GeneralRe: Lovin' it! PinmemberSacha Barber12-Dec-07 1:59 
GeneralRe: Lovin' it! PinmemberKarl Shifflett12-Dec-07 2:02 
GeneralRe: Lovin' it! PinmemberSacha Barber12-Dec-07 2:54 
GeneralRe: Lovin' it! PinmemberKarl Shifflett12-Dec-07 2:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140814.1 | Last Updated 18 Dec 2007
Article Copyright 2007 by Andrew Smith, Josh Smith, Karl Shifflett
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid