Skip to content

Commit 9cb834b

Browse files
pictosjfversluisCopilot
authored andcommitted
Enhance debugging in ViewHandler.cs (#29538)
* Enhance debugging in ViewHandler.cs Added System.Diagnostics for debugging support. Introduced DebuggerDisplay attribute to ViewHandler class and added GetDebuggerDisplay method to improve object state visibility during debugging. * Update src/Core/src/Handlers/View/ViewHandler.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Gerald Versluis <gerald@verslu.is> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d3c2146 commit 9cb834b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Core/src/Handlers/View/ViewHandler.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Maui.Graphics;
2+
using System.Diagnostics;
23
#if __IOS__ || MACCATALYST
34
using PlatformView = UIKit.UIView;
45
#elif __ANDROID__
@@ -18,6 +19,7 @@ namespace Microsoft.Maui.Handlers
1819
/// </summary>
1920
/// <remarks>Handlers map virtual views (.NET MAUI layer) to controls on each platform (iOS, Android, Windows, macOS, etc.), which are known as platform views.
2021
/// Handlers are also responsible for instantiating the underlying platform view, and mapping the cross-platform control API to the platform view API. </remarks>
22+
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
2123
public abstract partial class ViewHandler : ElementHandler, IViewHandler
2224
{
2325
/// <summary>
@@ -536,5 +538,20 @@ public static void MapToolTip(IViewHandler handler, IView view)
536538
handler.ToPlatform().UpdateToolTip(tooltipContainer.ToolTip);
537539
#endif
538540
}
541+
542+
/// <summary>
543+
/// Provides a string representation of the current object for debugging purposes.
544+
/// </summary>
545+
/// <remarks>
546+
/// This method is used by the <see cref="DebuggerDisplayAttribute"/> to display
547+
/// a concise and informative string representation of the <see cref="ViewHandler"/> instance
548+
/// during debugging sessions.
549+
/// </remarks>
550+
/// <returns>A string containing the type name and key properties of the object.</returns>
551+
private protected virtual string GetDebuggerDisplay()
552+
{
553+
var debugText = DebuggerDisplayHelpers.GetDebugText(nameof(VirtualView), VirtualView, nameof(PlatformView), PlatformView);
554+
return $"{GetType().FullName}: {debugText}";
555+
}
539556
}
540557
}

0 commit comments

Comments
 (0)