Skip to content

Commit

Permalink
MOQ Debugger Visualizer
Browse files Browse the repository at this point in the history
git-svn-id: http://moq.googlecode.com/svn/trunk@601 b33fba48-7441-0410-8d5c-f397f7ceaa6c
  • Loading branch information
marianoor committed Jul 22, 2009
1 parent 7c75c02 commit 9aa7993
Show file tree
Hide file tree
Showing 18 changed files with 766 additions and 27 deletions.
8 changes: 8 additions & 0 deletions Moq.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Silverlight", "Source.S
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Silverlight.Tests", "UnitTests.Silverlight\Moq.Silverlight.Tests.csproj", "{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Visualizer", "Visualizer\Moq.Visualizer.csproj", "{335EAF40-60EF-40D7-84A8-E33D255FA59F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -54,6 +56,12 @@ Global
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Release|Any CPU.Build.0 = Release|Any CPU
{02A2F6A6-D8CF-45EB-A424-BFD8C26034CE}.Release|x86.ActiveCfg = Release|Any CPU
{335EAF40-60EF-40D7-84A8-E33D255FA59F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{335EAF40-60EF-40D7-84A8-E33D255FA59F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{335EAF40-60EF-40D7-84A8-E33D255FA59F}.Debug|x86.ActiveCfg = Debug|Any CPU
{335EAF40-60EF-40D7-84A8-E33D255FA59F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{335EAF40-60EF-40D7-84A8-E33D255FA59F}.Release|Any CPU.Build.0 = Release|Any CPU
{335EAF40-60EF-40D7-84A8-E33D255FA59F}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 0 additions & 12 deletions Source/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,6 @@ private static string GetGenericArguments(IEnumerable<Type> arguments, bool useF
string.Join(",", arguments.Select(t => GetTypeName(t, useFullTypeName)).ToArray()) +
">";
}

//protected override Expression VisitUnary(UnaryExpression u)
//{
// if (u.NodeType == ExpressionType.Convert &&
// u.Operand.NodeType == ExpressionType.Call &&
// typeof(Match).IsAssignableFrom(((MethodCallExpression)u.Operand).Method.ReturnType))
// {
// return u.Operand;
// }

// return base.VisitUnary(u);
//}
}
}
}
31 changes: 16 additions & 15 deletions Source/ExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq.Expressions;

Expand Down Expand Up @@ -89,14 +90,24 @@ protected ExpressionVisitor()
/// Visits the <see cref="Expression"/>, determining which
/// of the concrete Visit methods to call.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
protected virtual Expression Visit(Expression exp)
{
if (exp == null)
return exp;

switch (exp.NodeType)
{
case ExpressionType.Parameter:
return this.VisitParameter((ParameterExpression)exp);
case ExpressionType.Call:
return this.VisitMethodCall((MethodCallExpression)exp);
case ExpressionType.Lambda:
return this.VisitLambda((LambdaExpression)exp);
case ExpressionType.Constant:
return this.VisitConstant((ConstantExpression)exp);
case ExpressionType.MemberAccess:
return this.VisitMemberAccess((MemberExpression)exp);
case ExpressionType.Negate:
case ExpressionType.NegateChecked:
case ExpressionType.Not:
Expand Down Expand Up @@ -130,20 +141,6 @@ protected virtual Expression Visit(Expression exp)
case ExpressionType.LeftShift:
case ExpressionType.ExclusiveOr:
return this.VisitBinary((BinaryExpression)exp);
case ExpressionType.TypeIs:
return this.VisitTypeIs((TypeBinaryExpression)exp);
case ExpressionType.Conditional:
return this.VisitConditional((ConditionalExpression)exp);
case ExpressionType.Constant:
return this.VisitConstant((ConstantExpression)exp);
case ExpressionType.Parameter:
return this.VisitParameter((ParameterExpression)exp);
case ExpressionType.MemberAccess:
return this.VisitMemberAccess((MemberExpression)exp);
case ExpressionType.Call:
return this.VisitMethodCall((MethodCallExpression)exp);
case ExpressionType.Lambda:
return this.VisitLambda((LambdaExpression)exp);
case ExpressionType.New:
return this.VisitNew((NewExpression)exp);
case ExpressionType.NewArrayInit:
Expand All @@ -153,6 +150,10 @@ protected virtual Expression Visit(Expression exp)
return this.VisitInvocation((InvocationExpression)exp);
case ExpressionType.MemberInit:
return this.VisitMemberInit((MemberInitExpression)exp);
case ExpressionType.TypeIs:
return this.VisitTypeIs((TypeBinaryExpression)exp);
case ExpressionType.Conditional:
return this.VisitConditional((ConditionalExpression)exp);
case ExpressionType.ListInit:
return this.VisitListInit((ListInitExpression)exp);
default:
Expand Down
47 changes: 47 additions & 0 deletions Visualizer/MemberExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Moq.Visualizer
{
internal static class MemberExtensions
{
public static string GetName(this MethodBase method)
{
if (method.IsGenericMethod)
{
return method.Name + GetGenericArguments(method.GetGenericArguments(), t => GetName(t));
}

return method.Name;
}

public static string GetFullName(this Type type)
{
if (type.IsGenericType)
{
return type.FullName.Substring(0, type.FullName.IndexOf('`')) +
GetGenericArguments(type.GetGenericArguments(), t => GetFullName(t));
}

return type.FullName;
}

public static string GetName(this Type type)
{
if (type.IsGenericType)
{
return type.Name.Substring(0, type.Name.IndexOf('`')) +
GetGenericArguments(type.GetGenericArguments(), t => GetName(t));
}

return type.Name;
}

private static string GetGenericArguments(IEnumerable<Type> types, Func<Type, string> typeGetter)
{
return "<" + string.Join(",", types.Select(typeGetter).ToArray()) + ">";
}
}
}
14 changes: 14 additions & 0 deletions Visualizer/MockVisualizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.VisualStudio.DebuggerVisualizers;

namespace Moq.Visualizer
{
public class MockVisualizer : DialogDebuggerVisualizer
{
protected override void Show(
IDialogVisualizerService windowService,
IVisualizerObjectProvider objectProvider)
{
windowService.ShowDialog(new MockVisualizerForm(objectProvider.GetObject()));
}
}
}
70 changes: 70 additions & 0 deletions Visualizer/MockVisualizerForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Visualizer/MockVisualizerForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Windows.Forms;
using Moq.Visualizer.ViewModel;

namespace Moq.Visualizer
{
public partial class MockVisualizerForm : Form
{
public MockVisualizerForm(object context)
{
this.InitializeComponent();
this.visualizerHost.HostContainer.DataContext = context;
}
}
}
120 changes: 120 additions & 0 deletions Visualizer/MockVisualizerForm.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Loading

0 comments on commit 9aa7993

Please sign in to comment.