|
|
|
|
@ -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; |
|
|
|
|
|