提交 69b1bdd2 编写于 作者: C Charles Stoner

Skip GetMemberValue for Nullable<T> error value

上级 6e5efac8
......@@ -2152,5 +2152,36 @@ protected class C : B
// Also need to check Access, StorageType, and TypeModifierFlags fields.
// ...
}
[WorkItem(1130978)]
[Fact]
public void NullableValue_Error()
{
var source =
@"class C
{
bool F() { return false; }
int? P
{
get
{
while (!F()) { }
return null;
}
}
}";
DkmClrRuntimeInstance runtime = null;
GetMemberValueDelegate getMemberValue = (v, m) => (m == "P") ? CreateErrorValue(runtime.GetType(typeof(int?)), "Function evaluation timed out") : null;
runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)), getMemberValue: getMemberValue);
using (runtime.Load())
{
var type = runtime.GetType("C");
var value = CreateDkmClrValue(type.Instantiate(), type: type);
var memberValue = value.GetMemberValue("P", (int)System.Reflection.MemberTypes.Property, "C", DefaultInspectionContext);
var evalResult = FormatResult("o.P", memberValue);
Verify(evalResult,
EvalFailedResult("o.P", "Function evaluation timed out", "int?", "o.P"));
}
}
}
}
......@@ -143,6 +143,8 @@ internal string GetUnderlyingString(DkmClrValue value, DkmInspectionContext insp
private string GetUnderlyingStringImpl(DkmClrValue value, DkmInspectionContext inspectionContext)
{
Debug.Assert(!value.IsError());
if (value.IsNull)
{
return null;
......@@ -167,22 +169,15 @@ private string GetUnderlyingStringImpl(DkmClrValue value, DkmInspectionContext i
else if (!IsPredefinedType(lmrType))
{
// Check for special cased non-primitives that have underlying strings
if (string.Equals(lmrType.FullName, "System.Data.SqlTypes.SqlString", StringComparison.Ordinal))
if (lmrType.IsType("System.Data.SqlTypes", "SqlString"))
{
var fieldValue = value.GetFieldValue(InternalWellKnownMemberNames.SqlStringValue, inspectionContext);
return fieldValue.HostObjectValue as string;
}
do
else if (lmrType.IsOrInheritsFrom("System.Xml.Linq", "XNode"))
{
if (string.Equals(lmrType.FullName, "System.Xml.Linq.XNode", StringComparison.Ordinal))
{
return value.EvaluateToString(inspectionContext);
}
lmrType = lmrType.BaseType;
return value.EvaluateToString(inspectionContext);
}
while (lmrType != null);
}
return null;
......
......@@ -595,11 +595,26 @@ private static bool IsMscorlibType(this Type type, string @namespace, string nam
return type.IsType(@namespace, name) /*&& type.Assembly.IsMscorlib()*/;
}
private static bool IsType(this Type type, string @namespace, string name)
internal static bool IsOrInheritsFrom(this Type type, string @namespace, string name)
{
do
{
if (type.IsType(@namespace, name))
{
return true;
}
type = type.BaseType;
}
while (type != null);
return false;
}
internal static bool IsType(this Type type, string @namespace, string name)
{
Debug.Assert((@namespace == null) || (@namespace.Length > 0)); // Type.Namespace is null not empty.
Debug.Assert(!string.IsNullOrEmpty(name));
return (type.Namespace == @namespace) && (type.Name == name);
return string.Equals(type.Namespace, @namespace, StringComparison.Ordinal) &&
string.Equals(type.Name, name, StringComparison.Ordinal);
}
}
}
......@@ -297,8 +297,12 @@ private static string GetTypeName(DkmInspectionContext inspectionContext, DkmClr
{
Debug.Assert(value.Type.GetProxyType() == null);
var nullableValue = value.GetNullableValue(inspectionContext);
if (nullableValue == null)
DkmClrValue nullableValue;
if (value.IsError())
{
expansion = null;
}
else if ((nullableValue = value.GetNullableValue(inspectionContext)) == null)
{
Debug.Assert(declaredType.Equals(value.Type.GetLmrType()));
// No expansion of "null".
......
......@@ -330,6 +330,11 @@ public DkmClrValue GetMemberValue(string MemberName, int MemberType, string Pare
throw new ArgumentNullException("inspectionContext");
}
if (this.IsError())
{
throw new InvalidOperationException();
}
var runtime = this.Type.RuntimeInstance;
var memberValue = runtime.GetMemberValue(this, MemberName);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册