Click here to Skip to main content
Licence CPOL
First Posted 11 Dec 2007
Views 36,324
Bookmarked 32 times

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

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.
1 vote, 7.1%
1

2
1 vote, 7.1%
3
2 votes, 14.3%
4
10 votes, 71.4%
5
4.76/5 - 14 votes
1 removed
μ 4.43, σa 2.03 [?]

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)

About the Authors

Andrew Smith

Architect
Infragistics, Inc.
United States United States

Member
Andrew currently works as an architect for Infragistics working with windows forms and WPF. You can check out his blog here.

Josh Smith

Technical Lead
Cynergy Systems
United States United States

Member

Follow on Twitter Follow on Twitter
Josh creates software, for iOS and Windows.
 
He works at Cynergy Systems as a Technical Lead.
 
Simplify your debugging life by installing his Mole 2010[^] debugging tool.
 
Check out his Advanced MVVM[^] book.
 
Visit his WPF blog[^] or stop by his iOS blog[^].

Karl Shifflett

Program Manager
Microsoft Corporation
United States United States

Member

Follow on Twitter Follow on Twitter
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.



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Layout  Per page   
  Refresh
GeneralSuggestion - Resource Visualizer PinmemberCyanide8:54 13 Dec '07  
GeneralRe: Suggestion - Resource Visualizer PinmemberKarl Shifflett17:48 13 Dec '07  
GeneralRe: Suggestion - Resource Visualizer PinmvpJosh Smith2:52 14 Dec '07  
GeneralRe: Suggestion - Resource Visualizer PinmemberCyanide4:31 14 Dec '07  
GeneralRe: Suggestion - Resource Visualizer PinmvpJosh Smith4:36 14 Dec '07  
General110, 767 KB PinmvpRama Krishna Vavilala7:58 11 Dec '07  
GeneralRe: 110, 767 KB PinmemberKarl Shifflett8:56 11 Dec '07  
Rama,
 
You are the Man. That value is actually produced by the submission wizard! I'll correct it ASAP. I'll have to forward this issue to Chris.
 
I have not slept in days so I missed it. Sleepy | :zzz: Thanks for backing me up. Smile | :)
 
Have a great day and enjoy Mole!
 
Cheers, Karl
 
Just a grain of sand on the worlds beaches.

GeneralRe: 110, 767 KB PinmemberKarl Shifflett9:00 11 Dec '07  
GeneralLove it, but... PinmemberKent Boogaart6:43 11 Dec '07  
GeneralRe: Love it, but... PinmvpJosh Smith6:50 11 Dec '07  
GeneralRe: Love it, but... PinmemberKarl Shifflett7:49 11 Dec '07  
GeneralRe: Love it, but... [modified] PinmemberKarl Shifflett12:01 11 Dec '07  
GeneralRe: Love it, but... PinmemberKent Boogaart23:48 11 Dec '07  
GeneralLovin' it! PinmvpJosh Smith4:57 11 Dec '07  
GeneralRe: Lovin' it! PinmemberKarl Shifflett5:37 11 Dec '07  
GeneralRe: Lovin' it! PinmvpJosh Smith5:40 11 Dec '07  
GeneralRe: Lovin' it! [modified] PinmemberKarl Shifflett5:54 11 Dec '07  
JokeRe: Lovin' it! PinmvpJosh Smith5:55 11 Dec '07  
GeneralRe: Lovin' it! PinmemberSacha Barber2:59 12 Dec '07  
GeneralRe: Lovin' it! PinmemberKarl Shifflett3:02 12 Dec '07  
GeneralRe: Lovin' it! PinmemberSacha Barber3:54 12 Dec '07  
GeneralRe: Lovin' it! PinmemberKarl Shifflett3:56 12 Dec '07  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 18 Dec 2007
Article Copyright 2007 by Andrew Smith, Josh Smith, Karl Shifflett
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid