Mole 2010 is Now Available

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
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
The Fields section has been collapsed.
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
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
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