finish review code style

This commit is contained in:
chinboy
2025-01-18 16:59:19 +08:00
committed by CHINBOY
parent f383dc8710
commit bd4d2ecc16
16 changed files with 158 additions and 179 deletions
@@ -1,3 +1,8 @@
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
using System.Collections.ObjectModel;
using System.Diagnostics;
@@ -134,7 +139,6 @@ internal class DataGridColumnCollection : ObservableCollection<DataGridColumn>
// insert the column into our internal list
ItemsInternal.Insert(columnIndexWithFiller, dataGridColumn);
dataGridColumn.Index = columnIndexWithFiller;
dataGridColumn.OwningGrid = _owningGrid;
dataGridColumn.RemoveEditingElement();
if (dataGridColumn.IsVisible)
{
@@ -3,7 +3,6 @@ using AtomUI.Controls.Utils;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
@@ -128,11 +127,11 @@ public class DataGridTextColumn : DataGridBoundColumn
{
base.OnPropertyChanged(change);
if (change.Property == FontFamilyProperty
|| change.Property == FontSizeProperty
|| change.Property == FontStyleProperty
|| change.Property == FontWeightProperty
|| change.Property == ForegroundProperty)
if (change.Property == FontFamilyProperty ||
change.Property == FontSizeProperty ||
change.Property == FontStyleProperty ||
change.Property == FontWeightProperty ||
change.Property == ForegroundProperty)
{
NotifyPropertyChanged(change.Property.Name);
}
@@ -1,3 +1,8 @@
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Reflection;
@@ -479,7 +484,7 @@ public partial class DataGrid
CurrentColumn == targetColumn)
{
// Column of the current cell is made invisible. Trying to move the current cell to a neighbor column. May throw an exception.
DataGridColumn? dataGridColumn = ColumnsInternal.GetNextVisibleColumn(targetColumn);
var dataGridColumn = ColumnsInternal.GetNextVisibleColumn(targetColumn);
if (dataGridColumn == null)
{
dataGridColumn = ColumnsInternal.GetPreviousVisibleNonFillerColumn(targetColumn);
@@ -756,7 +761,7 @@ public partial class DataGrid
_horizontalOffset -= GetEdgedColumnWidth(dataGridColumn);
}
if (_hScrollBar != null && _hScrollBar.IsVisible) //
if (_hScrollBar != null && _hScrollBar.IsVisible)
{
_hScrollBar.Value = _horizontalOffset;
}
@@ -862,7 +867,7 @@ public partial class DataGrid
if (scaleStarWeights)
{
double starRatio = (totalStarColumnsWidth + adjustment - remainingAdjustment) / totalStarColumnsWidth;
foreach (DataGridColumn starColumn in starColumns)
foreach (var starColumn in starColumns)
{
starColumn.SetWidthStarValue(Math.Min(double.MaxValue, starRatio * starColumn.Width.Value));
}
@@ -1156,21 +1161,15 @@ public partial class DataGrid
_negHorizontalOffset = 0;
return -1;
}
else
if (!MathUtils.AreClose(_negHorizontalOffset, _horizontalOffset))
{
if (!MathUtils.AreClose(_negHorizontalOffset, _horizontalOffset))
{
_negHorizontalOffset = 0;
}
return dataGridColumn.Index;
_negHorizontalOffset = 0;
}
}
else
{
_negHorizontalOffset = GetEdgedColumnWidth(dataGridColumn) - (cx - _horizontalOffset);
return dataGridColumn.Index;
}
_negHorizontalOffset = GetEdgedColumnWidth(dataGridColumn) - (cx - _horizontalOffset);
return dataGridColumn.Index;
}
private void CorrectColumnDisplayIndexesAfterDeletion(DataGridColumn deletedColumn)
@@ -1739,7 +1738,7 @@ public partial class DataGrid
private void AutoGenerateColumnsPrivate()
{
if (!_measured || (_autoGeneratingColumnOperationCount > 0))
if (!_measured || _autoGeneratingColumnOperationCount > 0)
{
// Reading the DataType when we generate columns could cause the CollectionView to
// raise a Reset if its Enumeration changed. In that case, we don't want to generate again.
+13 -10
View File
@@ -1,3 +1,8 @@
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
@@ -2910,15 +2915,13 @@ public partial class DataGrid
// If the new item is a root level element, it has no parent group, so create an empty RowGroupInfo
return new DataGridRowGroupInfo(null, true, -1, -1, -1);
}
else
foreach (int slot in RowGroupHeadersTable.GetIndexes())
{
foreach (int slot in RowGroupHeadersTable.GetIndexes())
DataGridRowGroupInfo? groupInfo = RowGroupHeadersTable.GetValueAt(slot);
if (groupInfo!.CollectionViewGroup!.Items == collection)
{
DataGridRowGroupInfo? groupInfo = RowGroupHeadersTable.GetValueAt(slot);
if (groupInfo!.CollectionViewGroup!.Items == collection)
{
return groupInfo;
}
return groupInfo;
}
}
@@ -3062,12 +3065,12 @@ public partial class DataGrid
return indexCount - _showDetailsTable.GetIndexCount(lowerBound, upperBound, false) -
RowGroupHeadersTable.GetIndexCount(lowerBound, upperBound);
}
else if (RowDetailsVisibilityMode == DataGridRowDetailsVisibilityMode.Collapsed)
if (RowDetailsVisibilityMode == DataGridRowDetailsVisibilityMode.Collapsed)
{
// Total rows with details explicitly turned on
return _showDetailsTable.GetIndexCount(lowerBound, upperBound, true);
}
else if (RowDetailsVisibilityMode == DataGridRowDetailsVisibilityMode.VisibleWhenSelected)
}
if (RowDetailsVisibilityMode == DataGridRowDetailsVisibilityMode.VisibleWhenSelected)
{
// Total number of remaining rows that are selected
return _selectedItems.GetIndexCount(lowerBound, upperBound);
+3 -3
View File
@@ -508,8 +508,8 @@ public partial class DataGrid : TemplatedControl
private static bool IsValidRowHeight(double value)
{
return double.IsNaN(value) ||
(value >= DataGridRow.DATAGRIDROW_minimumHeight &&
value <= DataGridRow.DATAGRIDROW_maximumHeight);
(value >= DataGridRow.MinimumHeight &&
value <= DataGridRow.MaximumHeight);
}
/// <summary>
@@ -843,7 +843,7 @@ public partial class DataGrid : TemplatedControl
// Update the RowDetails templates if necessary
if (_rowsPresenter != null)
{
foreach (DataGridRow row in GetAllRows())
foreach (var row in GetAllRows())
{
if (GetRowDetailsVisibility(row.Index))
{
@@ -64,7 +64,7 @@ internal class DataGridDisplayData
{
return _recyclableGroupHeaders.Pop();
}
else if (_fullyRecycledGroupHeaders.Count > 0)
if (_fullyRecycledGroupHeaders.Count > 0)
{
// For fully recycled rows, we need to set the Visibility back to Visible
var groupHeader = _fullyRecycledGroupHeaders.Pop();
@@ -227,7 +227,8 @@ internal class DataGridDisplayData
{
return _recyclableRows.Pop();
}
else if (_fullyRecycledRows.Count > 0)
if (_fullyRecycledRows.Count > 0)
{
// For fully recycled rows, we need to set the Visibility back to Visible
var row = _fullyRecycledRows.Pop();
@@ -125,10 +125,7 @@ public class DataGridLengthConverter : TypeConverter
// WPF returns Auto in this case as well
return DataGridLength.Auto;
}
else
{
return new DataGridLength(doubleValue);
}
return new DataGridLength(doubleValue);
}
/// <summary>
@@ -174,33 +171,30 @@ public class DataGridLengthConverter : TypeConverter
{
throw DataGridError.DataGridLengthConverter.InvalidDataGridLength("value");
}
else
// Convert dataGridLength to a string
switch (dataGridLength.Value.UnitType)
{
// Convert dataGridLength to a string
switch (dataGridLength.Value.UnitType)
{
// for Auto print out "Auto". value is always "1.0"
case DataGridLengthUnitType.Auto:
return "Auto";
// for Auto print out "Auto". value is always "1.0"
case DataGridLengthUnitType.Auto:
return "Auto";
case DataGridLengthUnitType.SizeToHeader:
return "SizeToHeader";
case DataGridLengthUnitType.SizeToHeader:
return "SizeToHeader";
case DataGridLengthUnitType.SizeToCells:
return "SizeToCells";
case DataGridLengthUnitType.SizeToCells:
return "SizeToCells";
// Star has one special case when value is "1.0".
// in this case drop value part and print only "Star"
case DataGridLengthUnitType.Star:
return (
MathUtilities.AreClose(1.0, dataGridLength.Value.Value)
? _starSuffix
: Convert.ToString(dataGridLength.Value.Value, culture ?? CultureInfo.CurrentCulture) +
DataGridLengthConverter._starSuffix);
// Star has one special case when value is "1.0".
// in this case drop value part and print only "Star"
case DataGridLengthUnitType.Star:
return (
MathUtilities.AreClose(1.0, dataGridLength.Value.Value)
? _starSuffix
: Convert.ToString(dataGridLength.Value.Value, culture ?? CultureInfo.CurrentCulture) +
DataGridLengthConverter._starSuffix);
default:
return (Convert.ToString(dataGridLength.Value.Value, culture ?? CultureInfo.CurrentCulture));
}
default:
return (Convert.ToString(dataGridLength.Value.Value, culture ?? CultureInfo.CurrentCulture));
}
}
}
+2 -2
View File
@@ -331,8 +331,8 @@ public class DataGridRowEditEndedEventArgs : EventArgs
/// <param name="editAction">The editing action that has been taken.</param>
public DataGridRowEditEndedEventArgs(DataGridRow row, DataGridEditAction editAction)
{
this.Row = row;
this.EditAction = editAction;
Row = row;
EditAction = editAction;
}
/// <summary>
+20 -20
View File
@@ -21,23 +21,23 @@ using DataGridFrozenGrid = AtomUI.Controls.Utils.DataGridFrozenGrid;
namespace AtomUI.Controls;
[TemplatePart(DATAGRIDROW_elementBottomGridLine, typeof(Rectangle))]
[TemplatePart(DATAGRIDROW_elementCells, typeof(DataGridCellsPresenter))]
[TemplatePart(DATAGRIDROW_elementDetails, typeof(DataGridDetailsPresenter))]
[TemplatePart(DATAGRIDROW_elementRoot, typeof(Panel))]
[TemplatePart(DATAGRIDROW_elementRowHeader, typeof(DataGridRowHeader))]
[PseudoClasses(":selected", ":editing", ":invalid")]
[TemplatePart(ElementBottomGridLinePC, typeof(Rectangle))]
[TemplatePart(ElementCellsPC, typeof(DataGridCellsPresenter))]
[TemplatePart(ElementDetailsPC, typeof(DataGridDetailsPresenter))]
[TemplatePart(ElementRootPC, typeof(Panel))]
[TemplatePart(ElementRowHeaderPC, typeof(DataGridRowHeader))]
[PseudoClasses(StdPseudoClass.Selected, StdPseudoClass.Editing, StdPseudoClass.Invalid)]
public class DataGridRow : TemplatedControl
{
private const byte DATAGRIDROW_defaultMinHeight = 0;
internal const int DATAGRIDROW_maximumHeight = 65536;
internal const double DATAGRIDROW_minimumHeight = 0;
private const byte DefaultMinHeight = 0;
internal const int MaximumHeight = 65536;
internal const double MinimumHeight = 0;
private const string DATAGRIDROW_elementBottomGridLine = "PART_BottomGridLine";
private const string DATAGRIDROW_elementCells = "PART_CellsPresenter";
private const string DATAGRIDROW_elementDetails = "PART_DetailsPresenter";
internal const string DATAGRIDROW_elementRoot = "PART_Root";
internal const string DATAGRIDROW_elementRowHeader = "PART_RowHeader";
private const string ElementBottomGridLinePC = "PART_BottomGridLine";
private const string ElementCellsPC = "PART_CellsPresenter";
private const string ElementDetailsPC = "PART_DetailsPresenter";
internal const string ElementRootPC = "PART_Root";
internal const string ElementRowHeaderPC = "PART_RowHeader";
private DataGridCellsPresenter? _cellsElement;
private DataGridCell? _fillerCell;
@@ -150,7 +150,7 @@ public class DataGridRow : TemplatedControl
/// </summary>
public DataGridRow()
{
MinHeight = DATAGRIDROW_defaultMinHeight;
MinHeight = DefaultMinHeight;
Index = -1;
IsValid = true;
@@ -527,7 +527,7 @@ public class DataGridRow : TemplatedControl
/// </summary>
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
RootElement = e.NameScope.Find<Panel>(DATAGRIDROW_elementRoot);
RootElement = e.NameScope.Find<Panel>(ElementRootPC);
if (RootElement != null)
{
ApplyState();
@@ -541,7 +541,7 @@ public class DataGridRow : TemplatedControl
updateVerticalScrollBar = true;
}
_cellsElement = e.NameScope.Find<DataGridCellsPresenter>(DATAGRIDROW_elementCells);
_cellsElement = e.NameScope.Find<DataGridCellsPresenter>(ElementCellsPC);
if (_cellsElement != null)
{
_cellsElement.OwningRow = this;
@@ -556,7 +556,7 @@ public class DataGridRow : TemplatedControl
}
}
_detailsElement = e.NameScope.Find<DataGridDetailsPresenter>(DATAGRIDROW_elementDetails);
_detailsElement = e.NameScope.Find<DataGridDetailsPresenter>(ElementDetailsPC);
if (_detailsElement != null && OwningGrid != null)
{
_detailsElement.OwningRow = this;
@@ -569,10 +569,10 @@ public class DataGridRow : TemplatedControl
}
}
_bottomGridLine = e.NameScope.Find<Rectangle>(DATAGRIDROW_elementBottomGridLine);
_bottomGridLine = e.NameScope.Find<Rectangle>(ElementBottomGridLinePC);
EnsureGridLines();
_headerElement = e.NameScope.Find<DataGridRowHeader>(DATAGRIDROW_elementRowHeader);
_headerElement = e.NameScope.Find<DataGridRowHeader>(ElementRowHeaderPC);
if (_headerElement != null)
{
_headerElement.Owner = this;
@@ -1,6 +1,7 @@
using System.Diagnostics;
using System.Reactive.Linq;
using AtomUI.Controls.Utils;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
@@ -12,19 +13,19 @@ using DataGridFrozenGrid = AtomUI.Controls.Utils.DataGridFrozenGrid;
namespace AtomUI.Controls;
[TemplatePart(DATAGRIDROWGROUPHEADER_expanderButton, typeof(ToggleButton))]
[TemplatePart(DATAGRIDROWGROUPHEADER_indentSpacer, typeof(Control))]
[TemplatePart(DATAGRIDROWGROUPHEADER_itemCountElement, typeof(TextBlock))]
[TemplatePart(DATAGRIDROWGROUPHEADER_propertyNameElement, typeof(TextBlock))]
[TemplatePart(DataGridRow.DATAGRIDROW_elementRoot, typeof(Panel))]
[TemplatePart(DataGridRow.DATAGRIDROW_elementRowHeader, typeof(DataGridRowHeader))]
[PseudoClasses(":pressed", ":current", ":expanded")]
[TemplatePart(ExpanderButtonPC, typeof(ToggleButton))]
[TemplatePart(IndentSpacerPC, typeof(Control))]
[TemplatePart(ItemCountElementPC, typeof(TextBlock))]
[TemplatePart(PropertyNameElementPC, typeof(TextBlock))]
[TemplatePart(DataGridRow.ElementRootPC, typeof(Panel))]
[TemplatePart(DataGridRow.ElementRowHeaderPC, typeof(DataGridRowHeader))]
[PseudoClasses(StdPseudoClass.Pressed, StdPseudoClass.Current, StdPseudoClass.Expanded)]
public class DataGridRowGroupHeader : TemplatedControl
{
private const string DATAGRIDROWGROUPHEADER_expanderButton = "PART_ExpanderButton";
private const string DATAGRIDROWGROUPHEADER_indentSpacer = "PART_IndentSpacer";
private const string DATAGRIDROWGROUPHEADER_itemCountElement = "PART_ItemCountElement";
private const string DATAGRIDROWGROUPHEADER_propertyNameElement = "PART_PropertyNameElement";
private const string ExpanderButtonPC = "PART_ExpanderButton";
private const string IndentSpacerPC = "PART_IndentSpacer";
private const string ItemCountElementPC = "PART_ItemCountElement";
private const string PropertyNameElementPC = "PART_PropertyNameElement";
private bool _areIsCheckedHandlersSuspended;
private ToggleButton? _expanderButton;
@@ -165,10 +166,10 @@ public class DataGridRowGroupHeader : TemplatedControl
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
_rootElement = e.NameScope.Find<Panel>(DataGridRow.DATAGRIDROW_elementRoot);
_rootElement = e.NameScope.Find<Panel>(DataGridRow.ElementRootPC);
_expanderButtonSubscription?.Dispose();
_expanderButton = e.NameScope.Find<ToggleButton>(DATAGRIDROWGROUPHEADER_expanderButton);
_expanderButton = e.NameScope.Find<ToggleButton>(ExpanderButtonPC);
if (_expanderButton != null)
{
EnsureExpanderButtonIsChecked();
@@ -178,21 +179,21 @@ public class DataGridRowGroupHeader : TemplatedControl
.Subscribe(v => OnExpanderButtonIsCheckedChanged(v));
}
_headerElement = e.NameScope.Find<DataGridRowHeader>(DataGridRow.DATAGRIDROW_elementRowHeader);
_headerElement = e.NameScope.Find<DataGridRowHeader>(DataGridRow.ElementRowHeaderPC);
if (_headerElement != null)
{
_headerElement.Owner = this;
EnsureHeaderVisibility();
}
_indentSpacer = e.NameScope.Find<Control>(DATAGRIDROWGROUPHEADER_indentSpacer);
_indentSpacer = e.NameScope.Find<Control>(IndentSpacerPC);
if (_indentSpacer != null)
{
_indentSpacer.Width = _totalIndent;
}
_itemCountElement = e.NameScope.Find<TextBlock>(DATAGRIDROWGROUPHEADER_itemCountElement);
_propertyNameElement = e.NameScope.Find<TextBlock>(DATAGRIDROWGROUPHEADER_propertyNameElement);
_itemCountElement = e.NameScope.Find<TextBlock>(ItemCountElementPC);
_propertyNameElement = e.NameScope.Find<TextBlock>(PropertyNameElementPC);
UpdateTitleElements();
}
@@ -1,4 +1,5 @@
using System.Diagnostics;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Automation;
using Avalonia.Controls;
@@ -12,11 +13,11 @@ namespace AtomUI.Controls;
/// <summary>
/// Represents an individual <see cref="T:Avalonia.Controls.DataGrid" /> row header.
/// </summary>
[TemplatePart(DATAGRIDROWHEADER_elementRootName, typeof(Control))]
[PseudoClasses(":invalid", ":selected", ":editing", ":current")]
[TemplatePart(ElementRootNamePC, typeof(Control))]
[PseudoClasses(StdPseudoClass.Invalid, StdPseudoClass.Selected, StdPseudoClass.Editing, StdPseudoClass.Current)]
public class DataGridRowHeader : ContentControl
{
private const string DATAGRIDROWHEADER_elementRootName = "PART_Root";
private const string ElementRootNamePC = "PART_Root";
private Control? _rootElement;
public static readonly StyledProperty<IBrush> SeparatorBrushProperty =
@@ -100,7 +101,7 @@ public class DataGridRowHeader : ContentControl
/// </summary>
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
_rootElement = e.NameScope.Find<Control>(DATAGRIDROWHEADER_elementRootName);
_rootElement = e.NameScope.Find<Control>(ElementRootNamePC);
if (_rootElement != null)
{
UpdatePseudoClasses();
@@ -142,20 +143,18 @@ public class DataGridRowHeader : ContentControl
{
if (OwningRow != null)
{
PseudoClasses.Set(":invalid", !OwningRow.IsValid);
PseudoClasses.Set(":selected", OwningRow.IsSelected);
PseudoClasses.Set(":editing", OwningRow.IsEditing);
PseudoClasses.Set(StdPseudoClass.Invalid, !OwningRow.IsValid);
PseudoClasses.Set(StdPseudoClass.Selected, OwningRow.IsSelected);
PseudoClasses.Set(StdPseudoClass.Editing, OwningRow.IsEditing);
if (OwningGrid != null)
{
PseudoClasses.Set(":current", OwningRow.Slot == OwningGrid.CurrentSlot);
PseudoClasses.Set(StdPseudoClass.Current, OwningRow.Slot == OwningGrid.CurrentSlot);
}
}
else if (OwningRowGroupHeader != null && OwningGrid != null)
{
PseudoClasses.Set(":current", OwningRowGroupHeader.RowGroupInfo?.Slot == OwningGrid.CurrentSlot);
PseudoClasses.Set(StdPseudoClass.Current, OwningRowGroupHeader.RowGroupInfo?.Slot == OwningGrid.CurrentSlot);
}
}
}
@@ -74,7 +74,7 @@ public sealed class DataGridRowsPresenter : Panel, IChildIndexProvider
OwningGrid.ColumnsInternal.VisibleEdgedColumnsWidth +
OwningGrid.ColumnsInternal.FillerColumn.FillerWidth;
double topEdge = -OwningGrid.NegVerticalOffset;
foreach (Control element in OwningGrid.DisplayData.GetScrollingElements())
foreach (var element in OwningGrid.DisplayData.GetScrollingElements())
{
if (element is DataGridRow row)
{
@@ -137,7 +137,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
public bool ContainsIndexAndValue(int index, T value)
{
var lowerRangeIndex = FindRangeIndex(index);
return ((IsCorrectRangeIndex(lowerRangeIndex, index)) && (_list[lowerRangeIndex].ContainsValue(value)));
return IsCorrectRangeIndex(lowerRangeIndex, index) && _list[lowerRangeIndex].ContainsValue(value);
}
/// <summary>
@@ -168,10 +168,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
return _list[rangeIndex].UpperBound + 1;
}
else
{
return targetIndex;
}
return targetIndex;
}
public int GetNextIndex(int index)
@@ -182,11 +179,8 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
{
return targetIndex;
}
else
{
rangeIndex++;
return rangeIndex < _list.Count ? _list[rangeIndex].LowerBound : -1;
}
rangeIndex++;
return rangeIndex < _list.Count ? _list[rangeIndex].LowerBound : -1;
}
public int GetPreviousGap(int index)
@@ -202,10 +196,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
return _list[rangeIndex].LowerBound - 1;
}
else
{
return targetIndex;
}
return targetIndex;
}
public int GetPreviousIndex(int index)
@@ -216,10 +207,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
{
return targetIndex;
}
else
{
return rangeIndex >= 0 && rangeIndex < _list.Count ? _list[rangeIndex].UpperBound : -1;
}
return rangeIndex >= 0 && rangeIndex < _list.Count ? _list[rangeIndex].UpperBound : -1;
}
/// <summary>
@@ -390,10 +378,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
{
return range.LowerBound + n - cumulatedEntries;
}
else
{
cumulatedEntries += range.Count;
}
cumulatedEntries += range.Count;
}
return -1;
@@ -423,11 +408,8 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
found = true;
return _list[rangeIndex].Value;
}
else
{
found = false;
return default;
}
found = false;
return default;
}
/// <summary>
@@ -445,10 +427,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
cumulatedIndexes += index - range.LowerBound;
break;
}
else
{
cumulatedIndexes += range.Count;
}
cumulatedIndexes += range.Count;
}
return cumulatedIndexes;
@@ -495,7 +474,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
Debug.Assert(count > 0);
var lowerRangeIndex = FindRangeIndex(startIndex);
InsertIndexesPrivate(startIndex, count, lowerRangeIndex);
if ((lowerRangeIndex >= 0) && (_list[lowerRangeIndex].LowerBound > startIndex))
if (lowerRangeIndex >= 0 && _list[lowerRangeIndex].LowerBound > startIndex)
{
// Because of the insert, the original range no longer contains the startIndex
lowerRangeIndex--;
@@ -618,7 +597,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
lowerRangeIndex = 0;
}
while ((lowerRangeIndex < _list.Count) && (_list[lowerRangeIndex].UpperBound < startIndex))
while (lowerRangeIndex < _list.Count && _list[lowerRangeIndex].UpperBound < startIndex)
{
lowerRangeIndex++;
}
@@ -712,7 +691,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
// At this point the newRange has been inserted in the correct place, now we need to remove
// any subsequent ranges that no longer make sense and possibly update the one at newRange.UpperBound
var upperRangeIndex = lowerRangeIndex + 1;
while ((upperRangeIndex < _list.Count) && (_list[upperRangeIndex].UpperBound < endIndex))
while (upperRangeIndex < _list.Count && _list[upperRangeIndex].UpperBound < endIndex)
{
_list.RemoveAt(upperRangeIndex);
}
@@ -771,17 +750,11 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
// we found it or the index isn't there and we're one range before
return front;
}
else
{
// not found and we're one range after
return front - 1;
}
}
else
{
// end is one index before front in this case so it's the range before
return end;
// not found and we're one range after
return front - 1;
}
// end is one index before front in this case so it's the range before
return end;
}
private bool Merge(int lowerRangeIndex)
@@ -808,7 +781,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
Debug.Assert(count > 0);
// Same as AddRange after we fix the indicies affected by the insertion
var startRangeIndex = (lowerRangeIndex >= 0) ? lowerRangeIndex : 0;
var startRangeIndex = lowerRangeIndex >= 0 ? lowerRangeIndex : 0;
for (var i = startRangeIndex; i < _list.Count; i++)
{
Range<T> range = _list[i];
@@ -837,7 +810,7 @@ internal class IndexToValueTable<T> : IEnumerable<Range<T>>
private bool IsCorrectRangeIndex(int rangeIndex, int index)
{
return (-1 != rangeIndex) && (_list[rangeIndex].ContainsIndex(index));
return -1 != rangeIndex && _list[rangeIndex].ContainsIndex(index);
}
private bool RemoveRangeIfInvalid(Range<T> range, int rangeIndex)
+1 -4
View File
@@ -33,10 +33,7 @@ internal class Range<T>
{
return value == null;
}
else
{
return Value.Equals(value);
}
return Value.Equals(value);
}
public Range<T> Copy()
@@ -151,7 +151,7 @@ internal static class TypeHelper
var type = parentType;
PropertyInfo? propertyInfo = null;
var propertyNames = SplitPropertyPath(propertyPath);
for (int i = 0; i < propertyNames.Count; i++)
for (var i = 0; i < propertyNames.Count; i++)
{
// if we can't find the property or it is not of the correct type,
// treat it as a null value
@@ -265,15 +265,15 @@ internal static class TypeHelper
if (elementType != null)
{
var genericList = typeof(List<>).MakeGenericType(elementType);
// If the object is of type IList, try to use its default indexer.
if (typeof(IList<>).MakeGenericType(elementType) is Type genericList
&& genericList.IsAssignableFrom(type))
if (genericList.IsAssignableFrom(type))
{
indexer = FindIndexerInMembers(genericList.GetDefaultMembers(), stringIndex, out index);
}
if (typeof(IReadOnlyList<>).MakeGenericType(elementType) is Type genericReadOnlyList
&& genericReadOnlyList.IsAssignableFrom(type))
var genericReadOnlyList = typeof(List<>).MakeGenericType(elementType);
if (genericReadOnlyList.IsAssignableFrom(type))
{
indexer = FindIndexerInMembers(genericReadOnlyList.GetDefaultMembers(), stringIndex, out index);
}
@@ -419,11 +419,20 @@ internal static class TypeHelper
{
// We haven't located a type yet.. try a different approach.
// Does the list have anything in it?
var enumerator = list.GetEnumerator();
if (enumerator.MoveNext() && enumerator.Current != null)
try
{
return enumerator.Current.GetType();
if (enumerator.MoveNext() && enumerator.Current != null)
{
return enumerator.Current.GetType();
}
}
finally
{
if (enumerator is IDisposable disposable)
{
disposable.Dispose();
}
}
}
@@ -41,8 +41,8 @@ internal static class ValidationUtil
{
if (oldValidationResult.ErrorMessage == target.ErrorMessage)
{
bool movedOld = true;
bool movedTarget = true;
bool movedOld = true;
bool movedTarget = true;
using IEnumerator<string> oldEnumerator = oldValidationResult.MemberNames.GetEnumerator();
using IEnumerator<string> targetEnumerator = target.MemberNames.GetEnumerator();
while (movedOld && movedTarget)
@@ -160,9 +160,9 @@ internal static class ValidationUtil
/// <returns>True if the process cannot be recovered from the exception.</returns>
public static bool IsCriticalException(Exception exception)
{
return (exception is OutOfMemoryException) ||
(exception is StackOverflowException) ||
(exception is AccessViolationException) ||
(exception is ThreadAbortException);
return exception is OutOfMemoryException ||
exception is StackOverflowException ||
exception is AccessViolationException ||
exception is ThreadAbortException;
}
}