Click here to Skip to main content
6,596,602 members and growing! (20,582 online)
Email Password   helpLost your password?
General Programming » Macros and Add-ins » VS.NET Addins     Intermediate

Special QuickWatch for a DataSet

By mohammed barqawi

A VS.NET add-in to know the content of the any dataset during debugging.
C#.NET 1.1, Win2K, WinXP, Win2003VS.NET2003, Dev
Posted:26 May 2004
Views:187,245
Bookmarked:135 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
Prize winner in Competition "C# Apr 2004"
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
104 votes for this article.
Popularity: 9.58 Rating: 4.75 out of 5
7 votes, 6.7%
1

2

3
5 votes, 4.8%
4
92 votes, 88.5%
5

Sample Image - Article.gif

Introduction

I am working on an ERP that is dealing with datasets a lot, and every time I need to know the contents of the dataset during debugging I try to make a quick watch but it has caused me headaches so I decided to make my own dataset quick watch.

How does it work?

I wrote my code using C#. I started by creating an Extensibility Projects from VS.NET's New Project menu. The wizard shows up and now the main idea behind this addin is how to pass an object from the VS.NET debug mode to the add-in. I did a lot of search but I did not find anything. The only way to know what is going in the debug mode is to use DTE.Debugger.GetExpression.

How did I insert my button in the context menu?

The wizard adds the created button (Command) in the Tools menu so I need to change the Tools to the context menu and to do that I replaced the Tools with Code Window, noting that the status for the command is (int)vsCommandStatus.vsCommandStatusUnsupported +(int)vsCommandStatus.vsCommandStatusInvisible to show it just when I need it:

// add the command to the right click context menu 

// note that when I insert the command it's inserted disabled

// "(int)vsCommandStatus.vsCommandStatusUnsupported +

// (int)vsCommandStatus.vsCommandStatusInvisible"


Command command = commands.AddNamedCommand ( addInInstance, DSWatchNode ,
        DataSet Quick Watch, DataSet Quick Watch, true, 60, ref contextGUIDS,
        (int)vsCommandStatus.vsCommandStatusUnsupported +
        (int)vsCommandStatus.vsCommandStatusInvisible ); 
CommandBar commandBar = (CommandBar)commandBars[Code Window]; 
CommandBarControl commandBarControl = command.AddControl(commandBar, 1); 
I have found a great article talking about addin and context menu in code project written by Erick Sgarbi called strongly typed collection and it was very useful

How to know if the selected test is a dataset?

After capturing the selected text i can use it as an expression in the Debugger.GetExpression() method of the application and evaluate anything I want. Now I will try to cast the selected text to dataset by evaluating the following:

string fileExtintion;
TextSelection _TextSelection;

_TextSelection = (TextSelection) applicationObject.ActiveDocument.Selection;

str = _TextSelection.Text;

fileExtintion=applicationObject.ActiveDocument.FullName.Substring(
                      applicationObject.ActiveDocument.FullName.Length-2 ) ;

switch(fileExtintion.ToLower() )
    {
    case "cs":
        isDataSetExpression="(System.Data.DataSet)"+str+".Tables";
        getXmlExpression="((System.Data.DataSet)"+str+").GetXml()";
        break;

    case"vb":
        isDataSetExpression="ctype("+ str +",System.Data.DataSet).Tables";
        getXmlExpression="ctype("+ str +",System.Data.DataSet).GetXml()";
        break;
    }

//cast the selcted text to dataset 

expr = debugger.GetExpression(isDataSetExpression,true,500);

if (expr.Value.IndexOf("error:")>-1)
{
    System.Windows.Forms.MessageBox.Show("This is not a DataSet!");
    return;
}

If the expr object does not have error message it will be a dataset:

if (expr.Value.IndexOf(error:)>-1) 
{
    System.Windows.Forms.MessageBox.Show(this is not DataSet!!);
    return;
} 

How to get the content of the dataset?

I could not get the object from the debugging project so I have to know the selected dataset XML contents by evaluating selectetDataSet.GetXML.

Using the code

Run the add-in setup file and after installing the add-in you will be able to watch any dataset by selecting it in the debug mode and choosing "DataSet Quick Watch" from right-click menu.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

mohammed barqawi


Member
web developer
email : mohammed.barqawi AT gmail.com
Occupation: Web Developer
Location: Jordan Jordan

Other popular Macros and Add-ins articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 102 (Total in Forum: 102) (Refresh)FirstPrevNext
GeneralGreat little tool PinmemberMember 38806121:30 10 Sep '09  
GeneralProblems with DsWatch in .net 2002 Pinmemberstvan9:38 21 May '09  
GeneralWoW!!!! Pinmemberpinkchand7:23 4 Apr '07  
GeneralProblem.................. Pinmemberfadee21:57 2 Aug '06  
GeneralRe: Problem.................. Pinmemberzipperle22:36 6 Sep '06  
GeneralRe: Problem.................. Pinmemberfadee3:32 7 Sep '06  
GeneralRe: Problem.................. Pinmemberzipperle21:56 10 Sep '06  
GeneralRe: Problem.................. Pinmemberfadee3:35 7 Sep '06  
QuestionHow to use the add-in as non-administrator account PinmemberBoudino0:21 23 Jun '06  
GeneralIt does not work at all PinmemberIhor Bobak10:04 1 Dec '05  
GeneralRe: It does not work at all PinmemberMika2:07 25 Apr '06  
GeneralRe: It does not work at all PinmemberGerardo_197823:08 8 May '06  
GeneralRe: It does not work at all PinmemberMika0:11 9 May '06  
GeneralRe: It does not work at all PinmemberGerardo_19786:14 9 May '06  
QuestionHow to use in VS2005 RTM Pinmembergroundie11:46 19 Nov '05  
AnswerRe: How to use in VS2005 RTM Pinmemberfcogarrido4:57 27 Dec '05  
GeneralRe: How to use in VS2005 RTM Pinmemberfcogarrido5:19 27 Dec '05  
GeneralRe: How to use in VS2005 RTM Pinmemberjason@myveryownwebsite.com7:46 24 Jan '06  
GeneralRe: How to use in VS2005 RTM PinmemberchristianArg4:26 8 Apr '08  
GeneralGood Job PinsussHamrosh ....:)22:44 21 Oct '05  
GeneralGreat Job! PinmemberGerald Gibson Jr7:29 10 Oct '05  
GeneralAnother fix - columns with all-null values disappeared PinmemberUri Dor2:27 25 Sep '05  
Generalproposed fix for "root invalid " error PinmemberUri Dor23:38 21 Sep '05  
GeneralWant your advise PinsussMo7ammed_Farid6:39 15 Jul '05  
GeneralGreat Tool... Pinmemberfadee23:49 8 Apr '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 26 May 2004
Editor: Heath Stewart
Copyright 2004 by mohammed barqawi
Everything else Copyright © CodeProject, 1999-2009
Web21 | Advertise on the Code Project