Skip to content

Commit

Permalink
Improve debugger display XP (#27489)
Browse files Browse the repository at this point in the history
* refactor DebuggerDisplay

* fix build

* removed unused method

* improve Helper method

* remove wrong attribute

* changed namespace to avoid conflicts
  • Loading branch information
pictos authored Feb 4, 2025
1 parent 398e747 commit be307a2
Show file tree
Hide file tree
Showing 27 changed files with 181 additions and 28 deletions.
4 changes: 3 additions & 1 deletion src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable
using System;
using System.Diagnostics;

using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
Expand Down Expand Up @@ -45,7 +46,8 @@ public IPlatformElementConfiguration<T, ActivityIndicator> On<T>() where T : ICo

private protected override string GetDebuggerDisplay()
{
return $"IsRunning = {IsRunning}, {base.GetDebuggerDisplay()}";
var debugText = DebuggerDisplayHelpers.GetDebugText(nameof(IsRunning), IsRunning);
return $"{base.GetDebuggerDisplay()}, {debugText}";
}
}
}
5 changes: 4 additions & 1 deletion src/Controls/src/Core/Button/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Microsoft.Maui.Controls.Internals;

using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
Expand Down Expand Up @@ -611,7 +612,9 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul

private protected override string GetDebuggerDisplay()
{
return $"Text = {Text}, Command = {Command}, {base.GetDebuggerDisplay()}";
var textString = DebuggerDisplayHelpers.GetDebugText(nameof(Text), Text);
var commandText = DebuggerDisplayHelpers.GetDebugText(nameof(Command), Command, false);
return $"{base.GetDebuggerDisplay()}, {textString}, {commandText}";
}
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/CheckBox/CheckBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bool ICheckBox.IsChecked

private protected override string GetDebuggerDisplay()
{
return $"IsChecked = {IsChecked}, {base.GetDebuggerDisplay()}";
return $"{base.GetDebuggerDisplay()}, IsChecked = {IsChecked}";
}
}
}
4 changes: 3 additions & 1 deletion src/Controls/src/Core/ContentPage/ContentPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Diagnostics;

using Microsoft.Maui.Graphics;
using Microsoft.Maui.HotReload;
using Microsoft.Maui.Layouts;
Expand Down Expand Up @@ -152,7 +153,8 @@ Size IContentView.CrossPlatformMeasure(double widthConstraint, double heightCons

private protected override string GetDebuggerDisplay()
{
return $"Content = {Content}, BindingContext = {BindingContext}";
var contentText = DebuggerDisplayHelpers.GetDebugText(nameof(Content), Content);
return $"{base.GetDebuggerDisplay()}, {contentText}";
}
}
}
4 changes: 3 additions & 1 deletion src/Controls/src/Core/ContentView/ContentView.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable disable
using System.Diagnostics;

using Microsoft.Maui.Graphics;
using Microsoft.Maui.Layouts;

Expand Down Expand Up @@ -51,7 +52,8 @@ internal override void SetChildInheritedBindingContext(Element child, object con

private protected override string GetDebuggerDisplay()
{
return $"Content = {Content}, {base.GetDebuggerDisplay()}";
var contentText = DebuggerDisplayHelpers.GetDebugText(nameof(Content), Content);
return $"{base.GetDebuggerDisplay()}, {contentText}";
}
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/DatePicker/DatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ string IDatePicker.Format

private protected override string GetDebuggerDisplay()
{
return $"Date = {Date}, {base.GetDebuggerDisplay()}";
return $"{base.GetDebuggerDisplay()}, Date = {Date}";
}
}
}
6 changes: 5 additions & 1 deletion src/Controls/src/Core/FlyoutPage/FlyoutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Microsoft.Maui.Controls.Internals;

using Microsoft.Maui.Devices;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/FlyoutPage.xml" path="Type[@FullName='Microsoft.Maui.Controls.FlyoutPage']/Docs/*" />
[ContentProperty(nameof(Detail))]
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class FlyoutPage : Page, IFlyoutPageController, IElementConfiguration<FlyoutPage>, IFlyoutView
{
/// <summary>Bindable property for <see cref="IsGestureEnabled"/>.</summary>
Expand Down Expand Up @@ -383,7 +386,8 @@ double IFlyoutView.FlyoutWidth
#endif
private protected override string GetDebuggerDisplay()
{
return $"DetailPage = {Detail}, FlyoutPage = {Flyout}, BindingContext = {BindingContext}";
var debugText = DebuggerDisplayHelpers.GetDebugText(nameof(Detail), Detail, "FlyoutPage", Flyout, nameof(BindingContext), BindingContext);
return $"{GetType().FullName}: {debugText}";
}
}
}
4 changes: 3 additions & 1 deletion src/Controls/src/Core/Image/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Diagnostics;


namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/Image.xml" path="Type[@FullName='Microsoft.Maui.Controls.Image']/Docs/*" />
Expand Down Expand Up @@ -108,7 +109,8 @@ void IImageSourcePart.UpdateIsLoading(bool isLoading) =>

private protected override string GetDebuggerDisplay()
{
return $"Source = {Source}, {base.GetDebuggerDisplay()}";
var sourceText = DebuggerDisplayHelpers.GetDebugText(nameof(Source), Source);
return $"{base.GetDebuggerDisplay()}, {sourceText}";
}
}
}
5 changes: 3 additions & 2 deletions src/Controls/src/Core/IndicatorView/IndicatorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
using System.Collections.Specialized;
using System.Diagnostics;
using Microsoft.Maui.Controls.Internals;

using Microsoft.Maui.Graphics;
using Microsoft.Maui.Layouts;

namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/IndicatorView.xml" path="Type[@FullName='Microsoft.Maui.Controls.IndicatorView']/Docs/*" />
[ContentProperty(nameof(IndicatorLayout))]

[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public partial class IndicatorView : TemplatedView, ITemplatedIndicatorView
{
Expand Down Expand Up @@ -199,7 +199,8 @@ int IIndicatorView.Position

private protected override string GetDebuggerDisplay()
{
return $"Position = {Position}, Count = {Count}, {base.GetDebuggerDisplay()}";
var debugText = DebuggerDisplayHelpers.GetDebugText(nameof(Position), Position, nameof(Count), Count);
return $"{base.GetDebuggerDisplay()}, {debugText}";
}
}
}
4 changes: 3 additions & 1 deletion src/Controls/src/Core/InputView/InputView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Diagnostics;
using Microsoft.Maui.Controls.Internals;

using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
Expand Down Expand Up @@ -276,7 +277,8 @@ string ITextInput.Text

private protected override string GetDebuggerDisplay()
{
return $"Text = {Text}, {base.GetDebuggerDisplay()}";
var debugText = DebuggerDisplayHelpers.GetDebugText(nameof(Text), Text);
return $"{base.GetDebuggerDisplay()}, Text = {debugText}";
}
}
}
6 changes: 5 additions & 1 deletion src/Controls/src/Core/Items/ItemsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Windows.Input;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Xaml.Diagnostics;

using Microsoft.Maui.Devices;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
{
/// <include file="../../../docs/Microsoft.Maui.Controls/ItemsView.xml" path="Type[@FullName='Microsoft.Maui.Controls.ItemsView']/Docs/*" />
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public abstract class ItemsView : View
{

Expand Down Expand Up @@ -228,7 +231,8 @@ protected override void OnBindingContextChanged()

private protected override string GetDebuggerDisplay()
{
return $"ItemsSource = {ItemsSource}, {base.GetDebuggerDisplay()}";
var itemsSourceText = DebuggerDisplayHelpers.GetDebugText(nameof(ItemsSource), ItemsSource);
return $"{base.GetDebuggerDisplay()}, {itemsSourceText}";
}
}
}
4 changes: 3 additions & 1 deletion src/Controls/src/Core/Label/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics;
using System.Linq;
using Microsoft.Maui.Controls.Internals;

using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
Expand Down Expand Up @@ -482,7 +483,8 @@ internal static bool TextChangedShouldInvalidateMeasure(Label label)

private protected override string GetDebuggerDisplay()
{
return $"Text = {Text}, {base.GetDebuggerDisplay()}";
var debugText = DebuggerDisplayHelpers.GetDebugText(nameof(Text), Text);
return $"{base.GetDebuggerDisplay()}, {debugText}";
}
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Layout/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ static void OnCascadeInputTransparentPropertyChanged(BindableObject bindable, ob

private protected override string GetDebuggerDisplay()
{
return $"ChildCount = {Count}, {base.GetDebuggerDisplay()}";
return $"{base.GetDebuggerDisplay()}, ChildCount = {Count}";
}
}
}
4 changes: 3 additions & 1 deletion src/Controls/src/Core/Page/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;

using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
Expand Down Expand Up @@ -943,7 +944,8 @@ public virtual Window GetParentWindow()

private protected override string GetDebuggerDisplay()
{
return $"BindingContext = {BindingContext}, Title = {Title}";
var debugText = DebuggerDisplayHelpers.GetDebugText(nameof(BindingContext), BindingContext, nameof(Title), Title);
return $"{this.GetType().FullName}: {debugText}";
}
}
}
4 changes: 3 additions & 1 deletion src/Controls/src/Core/Picker/Picker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Runtime.CompilerServices;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Xaml;

using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
Expand Down Expand Up @@ -465,7 +466,8 @@ string GetItem(int index)

private protected override string GetDebuggerDisplay()
{
return $"Items = {ItemsSource?.Count ?? 0}, SelectedItem = {SelectedItem}, {base.GetDebuggerDisplay()}";
var selectedItemText = DebuggerDisplayHelpers.GetDebugText(nameof(SelectedItem), SelectedItem);
return $"{base.GetDebuggerDisplay()}, Items = {ItemsSource?.Count ?? 0}, {selectedItemText}";
}
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/ProgressBar/ProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public IPlatformElementConfiguration<T, ProgressBar> On<T>() where T : IConfigPl

private protected override string GetDebuggerDisplay()
{
return $"Progress = {Progress}, {base.GetDebuggerDisplay()}";
return $"{base.GetDebuggerDisplay()}, Progress = {Progress}";
}
}
}
4 changes: 3 additions & 1 deletion src/Controls/src/Core/RadioButton/RadioButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Shapes;

using Microsoft.Maui.Devices;
using Microsoft.Maui.Graphics;

Expand Down Expand Up @@ -665,7 +666,8 @@ bool IRadioButton.IsChecked

private protected override string GetDebuggerDisplay()
{
return $"IsChecked = {IsChecked}, Value = {Value}, {base.GetDebuggerDisplay()}";
var debugText = DebuggerDisplayHelpers.GetDebugText(nameof(Value), Value, nameof(IsChecked), IsChecked);
return $"{base.GetDebuggerDisplay()},{debugText}";
}

private protected override Semantics UpdateSemantics()
Expand Down
4 changes: 3 additions & 1 deletion src/Controls/src/Core/RefreshView/RefreshView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Microsoft.Maui.Controls.Internals;

using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
Expand Down Expand Up @@ -152,7 +153,8 @@ bool IRefreshView.IsRefreshing

private protected override string GetDebuggerDisplay()
{
return $"Command = {Command}, IsRefreshing = {IsRefreshing}, {base.GetDebuggerDisplay()}";
var debugText = DebuggerDisplayHelpers.GetDebugText(nameof(Command), Command, nameof(IsRefreshing), IsRefreshing, false);
return $"{base.GetDebuggerDisplay()}, {debugText}";
}
}
}
4 changes: 3 additions & 1 deletion src/Controls/src/Core/ScrollView/ScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Maui.Controls.Internals;

using Microsoft.Maui.Graphics;
using Microsoft.Maui.Layouts;

Expand Down Expand Up @@ -484,7 +485,8 @@ private protected override void InvalidateMeasureLegacy(InvalidationTrigger trig

private protected override string GetDebuggerDisplay()
{
return $"Content = {Content}, {base.GetDebuggerDisplay()}";
var debugText = DebuggerDisplayHelpers.GetDebugText(nameof(Content), Content);
return $"{base.GetDebuggerDisplay()}, {debugText}";
}
}
}
4 changes: 3 additions & 1 deletion src/Controls/src/Core/SearchBar/SearchBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Windows.Input;
using Microsoft.Maui.Controls.Internals;

using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
Expand Down Expand Up @@ -167,7 +168,8 @@ void ISearchBar.SearchButtonPressed()

private protected override string GetDebuggerDisplay()
{
return $"SearchCommand = {SearchCommand}, {base.GetDebuggerDisplay()}";
var debugText = DebuggerDisplayHelpers.GetDebugText(nameof(SearchCommand), SearchCommand);
return $"{base.GetDebuggerDisplay()}, {debugText}";
}
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Slider/Slider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void ISlider.DragStarted()

private protected override string GetDebuggerDisplay()
{
return $"Value = {Value}, Min-Max = {Minimum} - {Maximum}, {base.GetDebuggerDisplay()}";
return $"{base.GetDebuggerDisplay()}, Value = {Value}, Min-Max = {Minimum} - {Maximum}";
}
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Stepper/Stepper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public double Value

private protected override string GetDebuggerDisplay()
{
return $"Value = {Value}, {base.GetDebuggerDisplay()}";
return $"{base.GetDebuggerDisplay()}, Value = {Value}";
}
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Switch/Switch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool ISwitch.IsOn

private protected override string GetDebuggerDisplay()
{
return $"IsToggled = {IsToggled}, {base.GetDebuggerDisplay()}";
return $"{base.GetDebuggerDisplay()}, IsToggled = {IsToggled}";
}
}
}
Loading

0 comments on commit be307a2

Please sign in to comment.