Skip to content

Commit

Permalink
use target typed new
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLarsson committed Apr 13, 2023
1 parent 4052b90 commit c4d8ef7
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 83 deletions.
2 changes: 1 addition & 1 deletion Gu.Wpf.DataGrid2D.Demo/Perf/BigDataGridViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Gu.Wpf.DataGrid2D.Demo

public sealed class BigDataGridViewModel : INotifyPropertyChanged
{
public static readonly BigDataGridViewModel Default = new BigDataGridViewModel();
public static readonly BigDataGridViewModel Default = new();
private string[]? rowHeaders;
private string[]? columnHeaders;
private int[,]? data2D;
Expand Down
6 changes: 3 additions & 3 deletions Gu.Wpf.DataGrid2D.Demo/TransposedVm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Gu.Wpf.DataGrid2D.Demo
namespace Gu.Wpf.DataGrid2D.Demo
{
using System.Collections.ObjectModel;

Expand All @@ -10,8 +10,8 @@ public TransposedVm()
this.Persons.Add(new Person { FirstName = "Erik", LastName = "Svensson" });
}

public ObservableCollection<Person> Persons { get; } = new ObservableCollection<Person>();
public ObservableCollection<Person> Persons { get; } = new();

public Person Person { get; } = new Person { FirstName = "Johan", LastName = "Larsson" };
public Person Person { get; } = new() { FirstName = "Johan", LastName = "Larsson" };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Gu.Wpf.DataGrid2D.Tests

public sealed class CollectionChangedEventArgsComparer : IComparer, IComparer<NotifyCollectionChangedEventArgs>
{
public static readonly CollectionChangedEventArgsComparer Default = new CollectionChangedEventArgsComparer();
public static readonly CollectionChangedEventArgsComparer Default = new();

private CollectionChangedEventArgsComparer()
{
Expand Down
20 changes: 10 additions & 10 deletions Gu.Wpf.DataGrid2D.Tests/ItemsSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public static void RowsSourceRemove()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1, 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 1, 2 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
var dataGrid = new DataGrid();
dataGrid.SetValue(ItemsSource.RowsSourceProperty, ints);
Expand Down Expand Up @@ -101,9 +101,9 @@ public static void RowsSourceAddRow()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1, 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 1, 2 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
var dataGrid = new DataGrid();
dataGrid.SetValue(ItemsSource.RowsSourceProperty, ints);
Expand Down Expand Up @@ -143,9 +143,9 @@ public static void ColumnsSource()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1, 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 1, 2 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
var dataGrid = new DataGrid();
dataGrid.SetValue(ItemsSource.ColumnsSourceProperty, ints);
Expand All @@ -164,7 +164,7 @@ public static void ColumnsSource()
[Test]
public static void TransposedSource()
{
var persons = new ObservableCollection<Person> { new Person { FirstName = "Johan", LastName = "Larsson" } };
var persons = new ObservableCollection<Person> { new() { FirstName = "Johan", LastName = "Larsson" } };
var dataGrid = new DataGrid();
dataGrid.SetValue(ItemsSource.TransposedSourceProperty, persons);
dataGrid.Initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public static void SignalsWhenColumnIsAdded()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1, 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new(new[] { 1, 2 }),
new(new[] { 3, 4 }),
};
using var view = new Lists2DTransposedView(ints);
var count = 0;
Expand All @@ -27,9 +27,9 @@ public static void SignalsWhenColumnIsRemoved()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 2 }),
new ObservableCollection<int>(new[] { 3 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 2 }),
new(new[] { 3 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DTransposedView(ints);
var count = 0;
Expand All @@ -43,9 +43,9 @@ public static void SignalsWhenColumnBecomesReadOnly()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1, 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 1, 2 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DTransposedView(ints);
var count = 0;
Expand All @@ -59,9 +59,9 @@ public static void SignalsWhenColumnBecomesReadOnly2()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 2, 3 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 2, 3 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DTransposedView(ints);
var count = 0;
Expand All @@ -75,9 +75,9 @@ public static void SignalsWhenColumnBecomesEditable()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 2 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DTransposedView(ints);
var count = 0;
Expand All @@ -91,9 +91,9 @@ public static void SignalsWhenColumnsBecomesEditable()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 2 }),
new ObservableCollection<int>(new[] { 3 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 2 }),
new(new[] { 3 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DTransposedView(ints);
var count = 0;
Expand All @@ -107,8 +107,8 @@ public static void NoChangeWhenAlreadyReadOnly()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1, 2 }),
new ObservableCollection<int>(new[] { 3, 4, 5 }),
new(new[] { 1, 2 }),
new(new[] { 3, 4, 5 }),
};
using var view = new Lists2DTransposedView(ints);
var count = 0;
Expand All @@ -122,9 +122,9 @@ public static void NoChangeWhenUpdateCell()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 1 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DTransposedView(ints);
var count = 0;
Expand Down
6 changes: 3 additions & 3 deletions Gu.Wpf.DataGrid2D.Tests/Views/Lists2DTransposedViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public static void CreateFromObservableCollections()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1, 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 1, 2 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DTransposedView(ints);
Assert.AreEqual(2, view.Count);
Expand Down
48 changes: 24 additions & 24 deletions Gu.Wpf.DataGrid2D.Tests/Views/Lists2DViewTests.ColumnsChanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public static void SignalsWhenColumnIsAdded()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 2, 3 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 2, 3 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DView(ints);
var count = 0;
Expand All @@ -28,9 +28,9 @@ public static void SignalsWhenColumnIsAdded2()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 2, 3 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 2, 3 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DView(ints);
var count = 0;
Expand All @@ -44,9 +44,9 @@ public static void SignalsWhenColumnIsRemoved()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 2 }),
new ObservableCollection<int>(new[] { 3 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 2 }),
new(new[] { 3 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DView(ints);
var count = 0;
Expand All @@ -60,9 +60,9 @@ public static void SignalsWhenColumnIsRemoved2()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 2 }),
new ObservableCollection<int>(new[] { 3 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 2 }),
new(new[] { 3 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DView(ints);
var count = 0;
Expand All @@ -76,9 +76,9 @@ public static void SignalsWhenColumnBecomesReadOnly()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1, 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 1, 2 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DView(ints);
var count = 0;
Expand All @@ -92,9 +92,9 @@ public static void SignalsWhenColumnBecomesEditable()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 2 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DView(ints);
var count = 0;
Expand All @@ -108,9 +108,9 @@ public static void NoChangeWhenAlreadyReadOnly()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 2 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DView(ints);
var count = 0;
Expand All @@ -124,9 +124,9 @@ public static void NoChangeWhenUpdateCell()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 1 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DView(ints);
var count = 0;
Expand Down
12 changes: 6 additions & 6 deletions Gu.Wpf.DataGrid2D.Tests/Views/Lists2DViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public static void CreateFromObservableCollections()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1, 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 1, 2 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DView(ints);
Assert.AreEqual(3, view.Count);
Expand Down Expand Up @@ -91,9 +91,9 @@ public static void ObservesAndNotifies()
{
var ints = new ObservableCollection<ObservableCollection<int>>
{
new ObservableCollection<int>(new[] { 1, 2 }),
new ObservableCollection<int>(new[] { 3, 4 }),
new ObservableCollection<int>(new[] { 5, 6 }),
new(new[] { 1, 2 }),
new(new[] { 3, 4 }),
new(new[] { 5, 6 }),
};
using var view = new Lists2DView(ints);
var expectedPropertyChanges = new List<string>();
Expand Down
6 changes: 3 additions & 3 deletions Gu.Wpf.DataGrid2D/Internals/Array2DIndexPropertyDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Gu.Wpf.DataGrid2D

internal class Array2DIndexPropertyDescriptor : IndexPropertyDescriptor
{
private static readonly ConcurrentDictionary<Key, PropertyDescriptorCollection> RowDescriptorCache = new ConcurrentDictionary<Key, PropertyDescriptorCollection>();
private static readonly ConcurrentDictionary<Key, PropertyDescriptorCollection> ColumnDescriptorCache = new ConcurrentDictionary<Key, PropertyDescriptorCollection>();
private static readonly ConcurrentDictionary<Key, PropertyDescriptorCollection> RowDescriptorCache = new();
private static readonly ConcurrentDictionary<Key, PropertyDescriptorCollection> ColumnDescriptorCache = new();

private Array2DIndexPropertyDescriptor(Type elementType, int index)
: base(elementType, index, isReadOnly: false)
Expand Down Expand Up @@ -89,7 +89,7 @@ static PropertyDescriptorCollection Create(Key key)

private struct Key : IEquatable<Key>
{
internal static readonly Key Empty = new Key(typeof(int), 0);
internal static readonly Key Empty = new(typeof(int), 0);

internal readonly Type ElementType;
internal readonly int Length;
Expand Down
5 changes: 2 additions & 3 deletions Gu.Wpf.DataGrid2D/Internals/BindingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ namespace Gu.Wpf.DataGrid2D

internal static class BindingHelper
{
private static readonly Dictionary<int, PropertyPath> IndexPaths = new Dictionary<int, PropertyPath>();
private static readonly Dictionary<int, PropertyPath> IndexPaths = new();

private static readonly Dictionary<DependencyProperty, PropertyPath> PropertyPaths =
new Dictionary<DependencyProperty, PropertyPath>();
private static readonly Dictionary<DependencyProperty, PropertyPath> PropertyPaths = new();

internal static BindingBuilder Bind(
this DependencyObject target,
Expand Down
2 changes: 1 addition & 1 deletion Gu.Wpf.DataGrid2D/RowColumnIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct RowColumnIndex : IEquatable<RowColumnIndex>
/// <summary>
/// No selection.
/// </summary>
public static readonly RowColumnIndex None = new RowColumnIndex(-1);
public static readonly RowColumnIndex None = new(-1);

/// <summary>
/// Initializes a new instance of the <see cref="RowColumnIndex"/> struct.
Expand Down
2 changes: 1 addition & 1 deletion Gu.Wpf.DataGrid2D/Views/Array2DView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Gu.Wpf.DataGrid2D
public class Array2DView : IList, IView2D
#pragma warning restore CA1010 // Collections should implement generic interface
{
private readonly WeakReference source = new WeakReference(null);
private readonly WeakReference source = new(null);
private readonly Array2DRowView[] rows;

private Array2DView(Array source, bool isTransposed)
Expand Down
Loading

0 comments on commit c4d8ef7

Please sign in to comment.