Skip to content

Commit ebc3146

Browse files
committed
refactor: Adjust Debug.Assert for Uno Platform compatibility
This changes aliases `System.Diagnostics.Debug` so that it does not conflict with Android's `View.Debug` property.
1 parent cb4dc66 commit ebc3146

19 files changed

+478
-440
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/CollectionViews/ListCollectionView.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using System.Reflection; // ConstructorInfo
1313
#endif
1414

15+
using DiagnosticsDebug = System.Diagnostics.Debug;
16+
1517
namespace Microsoft.Toolkit.Uwp.UI.Data.Utilities
1618
{
1719
/// <summary>
@@ -563,7 +565,7 @@ public object AddNew()
563565
BeginAddNew(newItem, index);
564566
}
565567

566-
Debug.Assert(_newItemIndex != -2 && object.Equals(newItem, _newItem), "AddNew did not raise expected events");
568+
DiagnosticsDebug.Assert(_newItemIndex != -2 && object.Equals(newItem, _newItem), "AddNew did not raise expected events");
567569

568570
MoveCurrentTo(newItem);
569571

@@ -588,7 +590,7 @@ public object AddNew()
588590
// related to AddNew. This method is called from ProcessCollectionChanged.
589591
private void BeginAddNew(object newItem, int index)
590592
{
591-
Debug.Assert(_newItemIndex == -2 && _newItem == NoNewItem, "unexpected call to BeginAddNew");
593+
DiagnosticsDebug.Assert(_newItemIndex == -2 && _newItem == NoNewItem, "unexpected call to BeginAddNew");
592594

593595
// remember the new item and its position in the underlying list
594596
SetNewItem(newItem);
@@ -810,7 +812,7 @@ private void SetNewItem(object item)
810812
{
811813
if (!object.Equals(item, _newItem))
812814
{
813-
Debug.Assert(item == NoNewItem || this._newItem == NoNewItem, "Old and new _newItem values are unexpectedly different from NoNewItem");
815+
DiagnosticsDebug.Assert(item == NoNewItem || this._newItem == NoNewItem, "Old and new _newItem values are unexpectedly different from NoNewItem");
814816
_newItem = item;
815817

816818
OnPropertyChanged(CurrentAddItemPropertyName);
@@ -1193,7 +1195,7 @@ private void SetEditItem(object item)
11931195
{
11941196
if (!object.Equals(item, _editItem))
11951197
{
1196-
Debug.Assert(item == null || _editItem == null, "Old and new _editItem values are unexpectedly non null");
1198+
DiagnosticsDebug.Assert(item == null || _editItem == null, "Old and new _editItem values are unexpectedly non null");
11971199
_editItem = item;
11981200

11991201
OnPropertyChanged(CurrentEditItemPropertyName);
@@ -1543,7 +1545,7 @@ private void ProcessCollectionChangedWithAdjustedIndex(EffectiveNotifyCollection
15431545
break;
15441546

15451547
default:
1546-
Debug.Assert(false, "Unexpected Effective Collection Change Action");
1548+
DiagnosticsDebug.Assert(false, "Unexpected Effective Collection Change Action");
15471549
break;
15481550
}
15491551

@@ -1571,7 +1573,7 @@ private void ProcessCollectionChangedWithAdjustedIndex(EffectiveNotifyCollection
15711573
// so any changes to the current item will only be raised once, and from this method
15721574
// _currentChangedMonitor is used to guard whether the CurrentChanged and CurrentChanging event can be fired
15731575
// so by entering it we're preventing the base calls from firing those events.
1574-
Debug.Assert(!CurrentChangedMonitor.Busy, "Expected _currentChangedMonitor.Busy is false.");
1576+
DiagnosticsDebug.Assert(!CurrentChangedMonitor.Busy, "Expected _currentChangedMonitor.Busy is false.");
15751577

15761578
CurrentChangedMonitor.Enter();
15771579
using (CurrentChangedMonitor)
@@ -1910,23 +1912,23 @@ private void Debug_ValidateCollectionChangedEventArgs(NotifyCollectionChangedEve
19101912
switch (e.Action)
19111913
{
19121914
case NotifyCollectionChangedAction.Add:
1913-
Debug.Assert(e.NewItems.Count == 1, "Unexpected NotifyCollectionChangedEventArgs.NewItems.Count for Add action");
1915+
DiagnosticsDebug.Assert(e.NewItems.Count == 1, "Unexpected NotifyCollectionChangedEventArgs.NewItems.Count for Add action");
19141916
break;
19151917

19161918
case NotifyCollectionChangedAction.Remove:
1917-
Debug.Assert(e.OldItems.Count == 1, "Unexpected NotifyCollectionChangedEventArgs.OldItems.Count for Remove action");
1919+
DiagnosticsDebug.Assert(e.OldItems.Count == 1, "Unexpected NotifyCollectionChangedEventArgs.OldItems.Count for Remove action");
19181920
break;
19191921

19201922
case NotifyCollectionChangedAction.Replace:
1921-
Debug.Assert(e.OldItems.Count == 1, "Unexpected NotifyCollectionChangedEventArgs.OldItems.Count for Replace action");
1922-
Debug.Assert(e.NewItems.Count == 1, "Unexpected NotifyCollectionChangedEventArgs.NewItems.Count for Replace action");
1923+
DiagnosticsDebug.Assert(e.OldItems.Count == 1, "Unexpected NotifyCollectionChangedEventArgs.OldItems.Count for Replace action");
1924+
DiagnosticsDebug.Assert(e.NewItems.Count == 1, "Unexpected NotifyCollectionChangedEventArgs.NewItems.Count for Replace action");
19231925
break;
19241926

19251927
case NotifyCollectionChangedAction.Reset:
19261928
break;
19271929

19281930
default:
1929-
Debug.Assert(false, "Unexpected NotifyCollectionChangedEventArgs action");
1931+
DiagnosticsDebug.Assert(false, "Unexpected NotifyCollectionChangedEventArgs action");
19301932
break;
19311933
}
19321934
}
@@ -2308,7 +2310,7 @@ private void SetSortDescriptions(SortDescriptionCollection descriptions)
23082310

23092311
if (_sort != null)
23102312
{
2311-
Debug.Assert(_sort.Count == 0, "must be empty SortDescription collection");
2313+
DiagnosticsDebug.Assert(_sort.Count == 0, "must be empty SortDescription collection");
23122314
((INotifyCollectionChanged)_sort).CollectionChanged += new NotifyCollectionChangedEventHandler(SortDescriptionsChanged);
23132315
}
23142316
}

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/Automation/DataGridAutomationPeer.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
using Windows.UI.Xaml.Controls.Primitives;
1616
using Windows.UI.Xaml.Data;
1717

18+
using DiagnosticsDebug = System.Diagnostics.Debug;
19+
1820
namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers
1921
{
2022
/// <summary>
@@ -286,8 +288,8 @@ IRawElementProviderSimple IGridProvider.GetItem(int row, int column)
286288
column++;
287289
}
288290

289-
Debug.Assert(column >= 0, "Expected positive column value.");
290-
Debug.Assert(column < this.OwningDataGrid.ColumnsItemsInternal.Count, "Expected smaller column value.");
291+
DiagnosticsDebug.Assert(column >= 0, "Expected positive column value.");
292+
DiagnosticsDebug.Assert(column < this.OwningDataGrid.ColumnsItemsInternal.Count, "Expected smaller column value.");
291293
DataGridCell cell = dgr.Cells[column];
292294
AutomationPeer peer = CreatePeerForElement(cell);
293295
if (peer != null)
@@ -557,8 +559,8 @@ private AutomationPeer GetCellPeer(int slot, int column)
557559
DataGridRow row = this.OwningDataGrid.DisplayData.GetDisplayedElement(slot) as DataGridRow;
558560
if (row != null)
559561
{
560-
Debug.Assert(column >= 0, "Expected positive column value.");
561-
Debug.Assert(column < this.OwningDataGrid.ColumnsItemsInternal.Count, "Expected smaller column value.");
562+
DiagnosticsDebug.Assert(column >= 0, "Expected positive column value.");
563+
DiagnosticsDebug.Assert(column < this.OwningDataGrid.ColumnsItemsInternal.Count, "Expected smaller column value.");
562564
DataGridCell cell = row.Cells[column];
563565
return CreatePeerForElement(cell);
564566
}

Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/Automation/DataGridGroupItemAutomationPeer.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using Windows.UI.Xaml.Automation.Provider;
1515
using Windows.UI.Xaml.Data;
1616

17+
using DiagnosticsDebug = System.Diagnostics.Debug;
18+
1719
namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers
1820
{
1921
/// <summary>
@@ -467,8 +469,8 @@ IRawElementProviderSimple IGridProvider.GetItem(int row, int column)
467469
{
468470
// Adjust the row index to be relative to the DataGrid instead of the group
469471
row = groupInfo.Slot - this.OwningDataGrid.RowGroupHeadersTable.GetIndexCount(0, groupInfo.Slot) + row + 1;
470-
Debug.Assert(row >= 0, "Expected positive row.");
471-
Debug.Assert(row < this.OwningDataGrid.DataConnection.Count, "Expected row smaller than this.OwningDataGrid.DataConnection.Count.");
472+
DiagnosticsDebug.Assert(row >= 0, "Expected positive row.");
473+
DiagnosticsDebug.Assert(row < this.OwningDataGrid.DataConnection.Count, "Expected row smaller than this.OwningDataGrid.DataConnection.Count.");
472474
int slot = this.OwningDataGrid.SlotFromRowIndex(row);
473475

474476
if (!this.OwningDataGrid.IsSlotVisible(slot))
@@ -477,12 +479,12 @@ IRawElementProviderSimple IGridProvider.GetItem(int row, int column)
477479
this.OwningDataGrid.ScrollIntoView(item, this.OwningDataGrid.Columns[column]);
478480
}
479481

480-
Debug.Assert(this.OwningDataGrid.IsSlotVisible(slot), "Expected OwningDataGrid.IsSlotVisible(slot) is true.");
482+
DiagnosticsDebug.Assert(this.OwningDataGrid.IsSlotVisible(slot), "Expected OwningDataGrid.IsSlotVisible(slot) is true.");
481483

482484
DataGridRow dgr = this.OwningDataGrid.DisplayData.GetDisplayedElement(slot) as DataGridRow;
483485

484486
// the first cell is always the indentation filler cell if grouping is enabled, so skip it
485-
Debug.Assert(column + 1 < dgr.Cells.Count, "Expected column + 1 smaller than dgr.Cells.Count.");
487+
DiagnosticsDebug.Assert(column + 1 < dgr.Cells.Count, "Expected column + 1 smaller than dgr.Cells.Count.");
486488
DataGridCell cell = dgr.Cells[column + 1];
487489
AutomationPeer peer = CreatePeerForElement(cell);
488490
if (peer != null)

0 commit comments

Comments
 (0)