public void Format(DbgDotNetValue value) { if (value is null) { throw new ArgumentNullException(nameof(value)); } evalInfo.CancellationToken.ThrowIfCancellationRequested(); try { if (recursionCounter++ >= MAX_RECURSION) { OutputWrite("???", DbgTextColor.Error); return; } if (TrySimpleFormat(value)) { return; } var type = value.Type; int tupleArity = TypeFormatterUtils.GetTupleArity(type); if (tupleArity > 0 && TryFormatTuple(value, tupleArity)) { return; } if (KeyValuePairTypeUtils.IsKeyValuePair(type) && TryFormatKeyValuePair(value, KeyValuePairTypeUtils.TryGetFields(value.Type))) { return; } if (DictionaryEntryTypeUtils.IsDictionaryEntry(type) && TryFormatKeyValuePair(value, DictionaryEntryTypeUtils.TryGetFields(value.Type))) { return; } if (TryFormatWithDebuggerAttributes(value)) { return; } if (TryFormatToString(value)) { return; } FormatTypeName(value); } finally { recursionCounter--; } }
bool TryFormatTuple(DbgDotNetValue value, int tupleArity) { Debug.Assert(TypeFormatterUtils.GetTupleArity(value.Type) == tupleArity && tupleArity > 0); OutputWrite(TupleTypeOpenParen, DbgTextColor.Punctuation); var values = ObjectCache.AllocDotNetValueList(); var runtime = evalInfo.Runtime.GetDotNetRuntime(); int index = 0; foreach (var info in TupleTypeUtils.GetTupleFields(value.Type, tupleArity)) { if (index++ > 0) { OutputWrite(",", DbgTextColor.Punctuation); WriteSpace(); } if (info.tupleIndex < 0) { OutputWrite("???", DbgTextColor.Error); break; } else { var objValue = value; DbgDotNetValueResult valueResult = default; try { foreach (var field in info.fields) { valueResult = runtime.LoadField(evalInfo, objValue, field); if (valueResult.Value != null) { values.Add(valueResult.Value); } if (valueResult.HasError || valueResult.ValueIsException) { objValue = null; break; } objValue = valueResult.Value; } valueResult = default; if (objValue == null) { OutputWrite("???", DbgTextColor.Error); break; } Format(objValue); } finally { valueResult.Value?.Dispose(); foreach (var v in values) { v?.Dispose(); } values.Clear(); } } } ObjectCache.Free(ref values); OutputWrite(TupleTypeCloseParen, DbgTextColor.Punctuation); return(true); }