Browse Source

Implemented TypeResolver properly, to support eg. finding IList<T> implementation on class MyClass : List<Person>.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4350 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Martin Koníček 17 years ago
parent
commit
16a6f9c97f
  1. 10
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/GridVisualizer/GridVisualizerWindow.xaml.cs
  2. 3
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/GridVisualizer/ValueProviders/ListValuesProvider.cs
  3. 77
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Utils/TypeResolver.cs

10
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/GridVisualizer/GridVisualizerWindow.xaml.cs

@ -41,7 +41,15 @@ namespace Debugger.AddIn.Visualizers.GridVisualizer @@ -41,7 +41,15 @@ namespace Debugger.AddIn.Visualizers.GridVisualizer
if (debuggerService == null)
throw new ApplicationException("Only windows debugger is currently supported");
Value val = debuggerService.GetValueFromName(txtExpression.Text);
Value val = null;
try
{
val = debuggerService.GetValueFromName(txtExpression.Text);
}
catch(GetValueException)
{
// display ex.Message
}
if (val != null && !val.IsNull)
{
DebugType iListType, listItemType;

3
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/GridVisualizer/ValueProviders/ListValuesProvider.cs

@ -10,6 +10,7 @@ using Debugger.MetaData; @@ -10,6 +10,7 @@ using Debugger.MetaData;
using ICSharpCode.SharpDevelop.Services;
using System.Collections;
using System.Collections.Generic;
using Debugger.AddIn.Visualizers.Utils;
namespace Debugger.AddIn.Visualizers.GridVisualizer
{
@ -60,7 +61,7 @@ namespace Debugger.AddIn.Visualizers.GridVisualizer @@ -60,7 +61,7 @@ namespace Debugger.AddIn.Visualizers.GridVisualizer
private int evaluateCount()
{
PropertyInfo countProperty = iListType.GetInterface(typeof(ICollection).FullName).GetProperty("Count");
PropertyInfo countProperty = iListType.GetGenericInterface("System.Collections.Generic.ICollection").GetProperty("Count");
Expression countExpr = targetObject.AppendPropertyReference(countProperty);
int count = 0;
try {

77
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Utils/TypeResolver.cs

@ -8,6 +8,7 @@ using System; @@ -8,6 +8,7 @@ using System;
using System.Collections;
using Debugger.MetaData;
using System.Collections.Generic;
using System.Linq;
namespace Debugger.AddIn.Visualizers.Utils
{
@ -16,47 +17,71 @@ namespace Debugger.AddIn.Visualizers.Utils @@ -16,47 +17,71 @@ namespace Debugger.AddIn.Visualizers.Utils
/// </summary>
public static class TypeResolverExtension
{
public static bool ResolveIListImplementation(this DebugType type, out DebugType iListType, out DebugType itemType)
/// <summary>
/// Gets generic interface this type implements.
/// The generic argument of the interface does not have to be specified.
/// If you know the generic argument, use DebugType.GetInterface.
/// </summary>
/// <param name="fullNamePrefix">Eg. "System.Collections.Generic.IList"</param>
public static DebugType GetGenericInterface(this DebugType type, string fullNamePrefix)
{
if (type == null)
throw new ArgumentNullException("type");
iListType = null;
itemType = null;
// alternative: search val.Type.Interfaces for IList<T>, from it, get T
// works when MyClass : IList<int>? - MyClass is not generic, yet can be displayed
iListType = type.GetInterface(typeof(IList).FullName);
if (iListType != null)
foreach(DebugType inter in type.Interfaces)
{
List<DebugType> genericArguments = type.GenericArguments;
if (genericArguments.Count == 1)
if (inter.FullName.StartsWith(fullNamePrefix) && inter.GenericArguments.Count > 0)
{
itemType = genericArguments[0];
return true;
return inter;
}
}
return false;
// not found, search BaseType
return type.BaseType == null ? null : type.BaseType.GetGenericInterface(fullNamePrefix);
}
/// <summary>
/// Resolves implementation of System.Collections.Generic.IList on this type.
/// </summary>
/// <param name="iListType">Result found implementation of System.Collections.Generic.IList.</param>
/// <param name="itemType">The only generic argument of <paramref name="implementation"/></param>
/// <returns>True if found, false otherwise.</returns>
public static bool ResolveIListImplementation(this DebugType type, out DebugType iListType, out DebugType itemType)
{
return type.ResolveGenericInterfaceImplementation(
"System.Collections.Generic.IList", out iListType, out itemType);
}
/// <summary>
/// Resolves implementation of System.Collections.Generic.IEnumerable on this type.
/// </summary>
/// <param name="iEnumerableType">Result found implementation of System.Collections.Generic.IEnumerable.</param>
/// <param name="itemType">The only generic argument of <paramref name="implementation"/></param>
/// <returns>True if found, false otherwise.</returns>
public static bool ResolveIEnumerableImplementation(this DebugType type, out DebugType iEnumerableType, out DebugType itemType)
{
return type.ResolveGenericInterfaceImplementation(
"System.Collections.Generic.IEnumerable", out iEnumerableType, out itemType);
}
/// <summary>
/// Resolves implementation of a single-generic-argument interface on this type.
/// </summary>
/// <param name="fullNamePrefix">Interface name to search for (eg. "System.Collections.Generic.IList")</param>
/// <param name="implementation">Result found implementation.</param>
/// <param name="itemType">The only generic argument of <paramref name="implementation"/></param>
/// <returns>True if found, false otherwise.</returns>
public static bool ResolveGenericInterfaceImplementation(this DebugType type, string fullNamePrefix, out DebugType implementation, out DebugType itemType)
{
if (type == null)
throw new ArgumentNullException("type");
iEnumerableType = null;
implementation = null;
itemType = null;
// works when MyClass : IEnumerable<int>? - MyClass is not generic, yet can be displayed
foreach (DebugType typeInterface in type.Interfaces)
implementation = type.GetGenericInterface(fullNamePrefix);
if (implementation != null)
{
if (typeInterface.FullName.StartsWith("System.Collections.Generic.IEnumerable"))
if (implementation.GenericArguments.Count == 1)
{
List<DebugType> genericArguments = typeInterface.GenericArguments;
if (genericArguments.Count == 1)
{
iEnumerableType = typeInterface;
itemType = genericArguments[0];
return true;
}
itemType = implementation.GenericArguments[0];
return true;
}
}
return false;

Loading…
Cancel
Save