Click here to Skip to main content
15,893,904 members
Articles / Programming Languages / C#

VSEDebug - VS.NET Debugging Enhancement

Rate me:
Please Sign up or sign in to vote.
4.92/5 (37 votes)
25 Apr 20049 min read 169.9K   2.2K   58  
VSEDebug is a VS.NET debugger add-in that adds the ability to debug complex types in simpler form.
using System;
using SynapticEffect.Forms;
using System.Runtime.InteropServices;

namespace vsedebug
{
	public class VSEUtil
	{
		
		
		[DllImport("user32.dll", CharSet=CharSet.Auto)]
		public static extern int SendMessage(
			IntPtr hWnd,
			System.UInt32 Msg,
			System.Int32 wParam,
			System.Int32 lParam);

		public enum DelayMode
		{
			none = 0,
			manualupdate = 1,
			delay = 2
		}

		public static EnvDTE._DTE ApplicationObject;
		public static EnvDTE.Debugger VSDebugger;
		public static int ElementsPerDivision = 10;
		public static int UpdateDelay = 275;
		public static DelayMode delaymode = DelayMode.manualupdate;
		public static int AutosLinesBefore = 1;
		public static int AutosLinesAfter = 0;
		public static System.Drawing.Font DisplayFont;

		/*
		 * Searches for a command in the commands collection that matches the key press event args that were
		 */

		/*
		 * Reads the settings file and sets the statics
		 */
		public static void ReadSettingsFile(string filepath)
		{
			String line;
			string[] halves;
			System.IO.StreamReader filereader = new System.IO.StreamReader(filepath);

			string familyname;
			float size;
			System.Drawing.FontStyle style;

			line = filereader.ReadLine();
			halves = line.Split(new char[]{'='}, 2);
			ElementsPerDivision = System.Convert.ToInt32(halves[1]);
			line = filereader.ReadLine();
			halves = line.Split(new char[]{'='}, 2);
			delaymode = (DelayMode)System.Convert.ToInt32(halves[1]);
			line = filereader.ReadLine();
			halves = line.Split(new char[]{'='}, 2);
			UpdateDelay = System.Convert.ToInt32(halves[1]);
			line = filereader.ReadLine();
			halves = line.Split(new char[]{'='}, 2);
			AutosLinesBefore = System.Convert.ToInt32(halves[1]);
			line = filereader.ReadLine();
			halves = line.Split(new char[]{'='}, 2);
			AutosLinesAfter = System.Convert.ToInt32(halves[1]);
			line = filereader.ReadLine();
			halves = line.Split(new char[]{'='}, 2);
			familyname = halves[1];
			line = filereader.ReadLine();
			halves = line.Split(new char[]{'='}, 2);
			size = (float)System.Convert.ToDouble(halves[1]);
			line = filereader.ReadLine();
			halves = line.Split(new char[]{'='}, 2);
			style = (System.Drawing.FontStyle)System.Convert.ToInt32(halves[1]);

			DisplayFont = new System.Drawing.Font(familyname, size, style);
		}
		/*
		 * Writes the settings file
		 */
		public static void WriteSettingsFile(string filepath)
		{
			System.IO.StreamWriter filewriter = new System.IO.StreamWriter(filepath, false);
			filewriter.WriteLine("ItemsPerDivision=" + ElementsPerDivision.ToString());
			filewriter.WriteLine("DelayMode=" + ((int)delaymode).ToString());
			filewriter.WriteLine("UpdateDelay=" + UpdateDelay.ToString());
			filewriter.WriteLine("AutosLinesBefore=" + AutosLinesBefore.ToString());
			filewriter.WriteLine("AutosLinesAfter=" + AutosLinesAfter.ToString());
			filewriter.WriteLine("FontFamily=" + DisplayFont.FontFamily.Name);
			filewriter.WriteLine("FontSize=" + DisplayFont.Size.ToString());
			filewriter.WriteLine("FontStyle=" + ((int)DisplayFont.Style).ToString());
			filewriter.Close();
		}
		/*
		 *	Rounds an integer up to the nearest multiple of nearestmult
		 */
		public static int RoundUp(int val, int nearestmult)
		{
			int mult = (val/nearestmult) + 1;
			return mult * nearestmult;
		}
		/*
		 *	Rounds an integer down to the nearest multiple of nearestmult
		 */
		public static int RoundDown(int val, int nearestmult)
		{
			int mult = (val/nearestmult);
			return mult * nearestmult;
		}

		/*
		 *	Generates a path to a variable.  For convenience
		 */
		public static String GenerateVariablePath(TreeListNode currentnode)
		{
			String path = currentnode.ExpressionText;
			//first, make sure we're not dealing with an array, which should not have .
			if(currentnode.Type.IndexOf("[") != -1)
			{
				return path;
			}
			//check to see what we need to put on the end...a . or a ->
			if(currentnode.Type.EndsWith("*") || currentnode.Name == "this")
			{
				path += "->";
			}
			else
			{
				path += ".";
			}
			return path;
		}
		/*
		 *	Deteremines whether the two expressions are equal up to a given depth
		 */
		public static bool ExpressionsAreEqual(EnvDTE.Expressions a, EnvDTE.Expressions b, int levels)
		{
			if(levels == 0) 
			{
				return true;
			}
			if(a == null || b == null)
			{
				return false;
			}
			//we're just checking the indicated number of levels of the expressions tree, to see whether the top level expressions are equal
			if(a.Count != b.Count)
			{
				return false;
			}

			for(int i = 1; i <= a.Count; i++) 
			{
				if(!ExpressionsAreEqual(a.Item(i), b.Item(i), levels))
				{
					return false;
				}
			}
			return true;
		}

		public static bool ExpressionsAreEqual(EnvDTE.Expression a, EnvDTE.Expression b, int levels)
		{
			if(levels == 0)
			{
				return true;
			}

			if(a == null || b == null)
			{
				return false;
			}
			if(a.Name != b.Name || a.Type != b.Type || a.Value != b.Value)
			{
				return false;
			}

			//we're just checking the indicated number of levels of the expressions tree, to see whether the top level expressions are equal
			if(a.DataMembers.Count != b.DataMembers.Count)
			{
				return false;
			}

			for(int i = 1; i <= a.DataMembers.Count; i++) 
			{
				//recurse
				if(!VSEUtil.ExpressionsAreEqual(a.DataMembers.Item(i).DataMembers, b.DataMembers.Item(i).DataMembers, levels-1))
				{
					return false;
				}
			}
			return true;
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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


Written By
Web Developer
United States United States
I'm a student at the University of Florida studying computer engineering.

You may find additional information about vsedebug at http://vsedebug.sourceforge.net

Comments and Discussions