Skip to content

Commit 4504a68

Browse files
pictosjfversluis
andauthored
Improve debugger experience (#27017)
* add debugger display on controls * more DebuggerDisplay * add ", " * Fix typo on SearchCommand Co-authored-by: Gerald Versluis <[email protected]> * fix typo in GetDebuggerDisplay * remove wrong attribute * fix typo in attribute * code style --------- Co-authored-by: Gerald Versluis <[email protected]>
1 parent 0f9dfdd commit 4504a68

File tree

27 files changed

+181
-1
lines changed

27 files changed

+181
-1
lines changed

src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#nullable disable
22
using System;
3+
using System.Diagnostics;
34
using Microsoft.Maui.Graphics;
45

56
namespace Microsoft.Maui.Controls
67
{
78
/// <include file="../../docs/Microsoft.Maui.Controls/ActivityIndicator.xml" path="Type[@FullName='Microsoft.Maui.Controls.ActivityIndicator']/Docs/*" />
9+
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
810
public partial class ActivityIndicator : View, IColorElement, IElementConfiguration<ActivityIndicator>, IActivityIndicator
911
{
1012
/// <summary>Bindable property for <see cref="IsRunning"/>.</summary>
@@ -40,5 +42,10 @@ public IPlatformElementConfiguration<T, ActivityIndicator> On<T>() where T : ICo
4042
{
4143
return _platformConfigurationRegistry.Value.On<T>();
4244
}
45+
46+
private protected override string GetDebuggerDisplay()
47+
{
48+
return $"IsRunning = {IsRunning}, {base.GetDebuggerDisplay()}";
49+
}
4350
}
4451
}

src/Controls/src/Core/Application/Application.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.ComponentModel;
5+
using System.Diagnostics;
56
using System.Diagnostics.CodeAnalysis;
67
using System.Threading;
78
using System.Threading.Tasks;

src/Controls/src/Core/Button/Button.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Microsoft.Maui.Controls
1313
/// <summary>
1414
/// A button <see cref="View" /> that reacts to touch events.
1515
/// </summary>
16+
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
1617
public partial class Button : View, IFontElement, ITextElement, IBorderElement, IButtonController, IElementConfiguration<Button>, IPaddingElement, IImageController, IViewController, IButtonElement, ICommandElement, IImageElement, IButton, ITextButton, IImageButton
1718
{
1819
const double DefaultSpacing = 10;
@@ -607,5 +608,10 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
607608
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
608609
=> throw new NotSupportedException();
609610
}
611+
612+
private protected override string GetDebuggerDisplay()
613+
{
614+
return $"Text = {Text}, Command = {Command}, {base.GetDebuggerDisplay()}";
615+
}
610616
}
611617
}

src/Controls/src/Core/CheckBox/CheckBox.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#nullable disable
22
using System;
3+
using System.Diagnostics;
34
using Microsoft.Maui.Graphics;
45

56
namespace Microsoft.Maui.Controls
67
{
78
/// <include file="../../docs/Microsoft.Maui.Controls/CheckBox.xml" path="Type[@FullName='Microsoft.Maui.Controls.CheckBox']/Docs/*" />
9+
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
810
public partial class CheckBox : View, IElementConfiguration<CheckBox>, IBorderElement, IColorElement, ICheckBox
911
{
1012
readonly Lazy<PlatformConfigurationRegistry<CheckBox>> _platformConfigurationRegistry;
@@ -79,5 +81,10 @@ bool ICheckBox.IsChecked
7981
get => IsChecked;
8082
set => SetValue(IsCheckedProperty, value, SetterSpecificity.FromHandler);
8183
}
84+
85+
private protected override string GetDebuggerDisplay()
86+
{
87+
return $"IsChecked = {IsChecked}, {base.GetDebuggerDisplay()}";
88+
}
8289
}
8390
}

src/Controls/src/Core/ContentPage/ContentPage.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#nullable disable
22

33
using System;
4+
using System.Diagnostics;
45
using Microsoft.Maui.Graphics;
56
using Microsoft.Maui.HotReload;
67
using Microsoft.Maui.Layouts;
@@ -9,6 +10,7 @@ namespace Microsoft.Maui.Controls
910
{
1011
/// <include file="../../docs/Microsoft.Maui.Controls/ContentPage.xml" path="Type[@FullName='Microsoft.Maui.Controls.ContentPage']/Docs/*" />
1112
[ContentProperty("Content")]
13+
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
1214
public partial class ContentPage : TemplatedPage, IContentView, HotReload.IHotReloadableView
1315
{
1416
/// <summary>Bindable property for <see cref="Content"/>.</summary>
@@ -147,5 +149,10 @@ Size IContentView.CrossPlatformMeasure(double widthConstraint, double heightCons
147149
{
148150
return (this as ICrossPlatformLayout).CrossPlatformMeasure(widthConstraint, heightConstraint);
149151
}
152+
153+
private protected override string GetDebuggerDisplay()
154+
{
155+
return $"Content = {Content}, BindingContext = {BindingContext}";
156+
}
150157
}
151158
}

src/Controls/src/Core/ContentView/ContentView.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#nullable disable
2+
using System.Diagnostics;
23
using Microsoft.Maui.Graphics;
34
using Microsoft.Maui.Layouts;
45

56
namespace Microsoft.Maui.Controls
67
{
78
/// <include file="../../docs/Microsoft.Maui.Controls/ContentView.xml" path="Type[@FullName='Microsoft.Maui.Controls.ContentView']/Docs/*" />
89
[ContentProperty("Content")]
10+
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
911
public partial class ContentView : TemplatedView, IContentView
1012
{
1113
/// <summary>Bindable property for <see cref="Content"/>.</summary>
@@ -46,5 +48,10 @@ internal override void SetChildInheritedBindingContext(Element child, object con
4648
object IContentView.Content => Content;
4749

4850
IView IContentView.PresentedContent => ((this as IControlTemplated).TemplateRoot as IView) ?? Content;
51+
52+
private protected override string GetDebuggerDisplay()
53+
{
54+
return $"Content = {Content}, {base.GetDebuggerDisplay()}";
55+
}
4956
}
5057
}

src/Controls/src/Core/DatePicker/DatePicker.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#nullable disable
22
using System;
3+
using System.Diagnostics;
34
using Microsoft.Maui.Controls.Internals;
45
using Microsoft.Maui.Graphics;
56

67
namespace Microsoft.Maui.Controls
78
{
89
/// <include file="../../docs/Microsoft.Maui.Controls/DatePicker.xml" path="Type[@FullName='Microsoft.Maui.Controls.DatePicker']/Docs/*" />
10+
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
911
public partial class DatePicker : View, IFontElement, ITextElement, IElementConfiguration<DatePicker>, IDatePicker
1012
{
1113
/// <summary>Bindable property for <see cref="Format"/>.</summary>
@@ -239,5 +241,10 @@ string IDatePicker.Format
239241
get => Format;
240242
set => SetValue(FormatProperty, value, SetterSpecificity.FromHandler);
241243
}
244+
245+
private protected override string GetDebuggerDisplay()
246+
{
247+
return $"Date = {Date}, {base.GetDebuggerDisplay()}";
248+
}
242249
}
243250
}

src/Controls/src/Core/FlyoutPage/FlyoutPage.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,5 +381,9 @@ double IFlyoutView.FlyoutWidth
381381
#else
382382
double IFlyoutView.FlyoutWidth => -1;
383383
#endif
384+
private protected override string GetDebuggerDisplay()
385+
{
386+
return $"DetailPage = {Detail}, FlyoutPage = {Flyout}, BindingContext = {BindingContext}";
387+
}
384388
}
385389
}

src/Controls/src/Core/Image/Image.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#nullable disable
22
using System;
33
using System.ComponentModel;
4+
using System.Diagnostics;
45

56
namespace Microsoft.Maui.Controls
67
{
78
/// <include file="../../docs/Microsoft.Maui.Controls/Image.xml" path="Type[@FullName='Microsoft.Maui.Controls.Image']/Docs/*" />
9+
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
810
public partial class Image : View, IImageController, IElementConfiguration<Image>, IViewController, IImageElement, IImage
911
{
1012
/// <summary>Bindable property for <see cref="Source"/>.</summary>
@@ -103,5 +105,10 @@ void IImageElement.RaiseImageSourcePropertyChanged() =>
103105

104106
void IImageSourcePart.UpdateIsLoading(bool isLoading) =>
105107
IsLoading = isLoading;
108+
109+
private protected override string GetDebuggerDisplay()
110+
{
111+
return $"Source = {Source}, {base.GetDebuggerDisplay()}";
112+
}
106113
}
107114
}

src/Controls/src/Core/IndicatorView/IndicatorView.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections;
44
using System.Collections.Specialized;
5+
using System.Diagnostics;
56
using Microsoft.Maui.Controls.Internals;
67
using Microsoft.Maui.Graphics;
78
using Microsoft.Maui.Layouts;
@@ -10,6 +11,8 @@ namespace Microsoft.Maui.Controls
1011
{
1112
/// <include file="../../docs/Microsoft.Maui.Controls/IndicatorView.xml" path="Type[@FullName='Microsoft.Maui.Controls.IndicatorView']/Docs/*" />
1213
[ContentProperty(nameof(IndicatorLayout))]
14+
15+
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
1316
public partial class IndicatorView : TemplatedView, ITemplatedIndicatorView
1417
{
1518
const int DefaultPadding = 4;
@@ -193,5 +196,10 @@ int IIndicatorView.Position
193196
get => Position;
194197
set => SetValue(PositionProperty, value, SetterSpecificity.FromHandler);
195198
}
199+
200+
private protected override string GetDebuggerDisplay()
201+
{
202+
return $"Position = {Position}, Count = {Count}, {base.GetDebuggerDisplay()}";
203+
}
196204
}
197205
}

0 commit comments

Comments
 (0)