DisplayPart[] GetDisplayParts(DmdType type) { var ddaType = type.AppDomain.GetWellKnownType(DmdWellKnownType.System_Diagnostics_DebuggerDisplayAttribute, isOptional: true); Debug.Assert((object)ddaType != null); if ((object)ddaType == null) { return(null); } string debuggerDisplayString; var attr = type.FindCustomAttribute(ddaType, inherit: true); if (attr == null) { if (type.CanCastTo(type.AppDomain.System_Type)) { // Show the same thing VS shows debuggerDisplayString = @"\{Name = {Name} FullName = {FullName}\}"; } else { return(null); } } else { if (attr.ConstructorArguments.Count == 1) { debuggerDisplayString = attr.ConstructorArguments[0].Value as string; } else { debuggerDisplayString = null; } } if (string.IsNullOrEmpty(debuggerDisplayString)) { return(null); } return(CreateDisplayParts(debuggerDisplayString)); }
(DisplayPart[] nameParts, DisplayPart[] valueParts, DisplayPart[] typeParts) GetDisplayParts(DmdType type) { var ddaType = type.AppDomain.GetWellKnownType(DmdWellKnownType.System_Diagnostics_DebuggerDisplayAttribute, isOptional: true); Debug.Assert((object)ddaType != null); // We have special support for formatting KeyValuePair<K, V>, so ignore all DebuggerDisplayAttributes. // (Only Unity and older Mono versions have a DebuggerDisplayAttribute on it) bool forceNoAttr = type.IsConstructedGenericType && type.GetGenericTypeDefinition() == type.AppDomain.GetWellKnownType(DmdWellKnownType.System_Collections_Generic_KeyValuePair_T2, isOptional: true); string nameDisplayString = null, valueDisplayString = null, typeDisplayString = null; if (!forceNoAttr && (object)ddaType != null) { var attr = type.FindCustomAttribute(ddaType, inherit: true); if (attr == null) { if (type.CanCastTo(type.AppDomain.System_Type)) { // Show the same thing VS shows valueDisplayString = @"\{Name = {Name} FullName = {FullName}\}"; } } else { if (attr.ConstructorArguments.Count == 1) { valueDisplayString = attr.ConstructorArguments[0].Value as string; } nameDisplayString = GetString(attr, nameof(DebuggerDisplayAttribute.Name)); typeDisplayString = GetString(attr, nameof(DebuggerDisplayAttribute.Type)); } } var nameParts = CreateDisplayParts(nameDisplayString); var valueParts = CreateDisplayParts(valueDisplayString); var typeParts = CreateDisplayParts(typeDisplayString); return(nameParts, valueParts, typeParts); }
(DisplayPart[] nameParts, DisplayPart[] valueParts, DisplayPart[] typeParts) GetDisplayParts(DmdType type) { var ddaType = type.AppDomain.GetWellKnownType(DmdWellKnownType.System_Diagnostics_DebuggerDisplayAttribute, isOptional: true); Debug2.Assert(ddaType is not null); bool forceNoAttr = ShouldIgnoreDebuggerDisplayAttribute(type); string?nameDisplayString = null, valueDisplayString = null, typeDisplayString = null; if (!forceNoAttr && ddaType is not null) { var attr = type.FindCustomAttribute(ddaType, inherit: true); if (attr is null) { if (type.CanCastTo(type.AppDomain.System_Type)) { // Show the same thing VS shows valueDisplayString = @"\{Name = {Name} FullName = {FullName}\}"; } } else { if (attr.ConstructorArguments.Count == 1) { valueDisplayString = attr.ConstructorArguments[0].Value as string; } nameDisplayString = GetString(attr, nameof(DebuggerDisplayAttribute.Name)); typeDisplayString = GetString(attr, nameof(DebuggerDisplayAttribute.Type)); } } var nameParts = CreateDisplayParts(nameDisplayString); var valueParts = CreateDisplayParts(valueDisplayString); var typeParts = CreateDisplayParts(typeDisplayString); return(nameParts, valueParts, typeParts); }