Browse Source

Fix NullReference exception in IsDisplayClass.

Add IsKnownType helper.
newNRvisualizers
David Srbecký 13 years ago
parent
commit
b842abccbd
  1. 4
      src/AddIns/Debugger/Debugger.AddIn/TreeModel/ValueNode.cs
  2. 12
      src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs
  3. 3
      src/AddIns/Debugger/Debugger.Core/Value.cs

4
src/AddIns/Debugger/Debugger.AddIn/TreeModel/ValueNode.cs

@ -123,7 +123,7 @@ namespace Debugger.AddIn.TreeModel @@ -123,7 +123,7 @@ namespace Debugger.AddIn.TreeModel
this.GetChildren = () => GetArrayChildren(dims, dims);
}
} else if (val.Type.Kind == TypeKind.Class || val.Type.Kind == TypeKind.Struct) {
if (val.Type.FullName == typeof(List<>).FullName) {
if (val.Type.IsKnownType(typeof(List<>))) {
if ((int)val.GetFieldValue("_size").PrimitiveValue > 0)
this.GetChildren = () => GetIListChildren(this.GetValue);
} else {
@ -355,7 +355,7 @@ namespace Debugger.AddIn.TreeModel @@ -355,7 +355,7 @@ namespace Debugger.AddIn.TreeModel
);
}
if (shownType.GetAllBaseTypeDefinitions().Any(t => t.FullName == typeof(IList).FullName)) {
if (shownType.GetAllBaseTypeDefinitions().Any(t => t.IsKnownType(typeof(IList)))) {
yield return new TreeNode(
"IList",
() => GetIListChildren(GetValue)

12
src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs

@ -375,6 +375,16 @@ namespace Debugger @@ -375,6 +375,16 @@ namespace Debugger
return def != null && def.KnownTypeCode == knownType;
}
public static bool IsKnownType(this IType type, Type knownType)
{
var def = type.GetDefinition();
if (knownType.IsGenericTypeDefinition) {
return def != null && def.Compilation.FindType(knownType).Equals(def);
} else {
return def != null && def.Compilation.FindType(knownType).Equals(type);
}
}
public static IField GetBackingField(this IMethod method)
{
return null;
@ -405,7 +415,7 @@ namespace Debugger @@ -405,7 +415,7 @@ namespace Debugger
return true; // Anonymous method or lambda
}
if (type.GetDefinition().Attributes.Any(a => a.AttributeType.FullName == typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute).FullName)) {
if (type.GetDefinition() != null && type.GetDefinition().Attributes.Any(a => a.AttributeType.IsKnownType(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)))) {
if (type.GetAllBaseTypeDefinitions().Any(t => t.FullName == typeof(System.Collections.IEnumerator).FullName)) {
return true; // yield
}

3
src/AddIns/Debugger/Debugger.Core/Value.cs

@ -493,6 +493,9 @@ namespace Debugger @@ -493,6 +493,9 @@ namespace Debugger
return objectInstance.CorObjectValue.GetFieldValue((fieldInfo.DeclaringType).ToCorDebug().GetClass(), fieldInfo.GetMetadataToken());
}
} catch (COMException e) {
// System.Runtime.InteropServices.COMException (0x80131303): A class is not loaded. (Exception from HRESULT: 0x80131303)
if ((uint)e.ErrorCode == 0x80131303)
throw new GetValueException("Class " + fieldInfo.DeclaringType.FullName + " is not loaded");
throw new GetValueException("Can not get value of field", e);
}
}

Loading…
Cancel
Save