Skip to content

Commit

Permalink
Merge pull request #209 from symbiogenesis/net9
Browse files Browse the repository at this point in the history
update to .NET 9
  • Loading branch information
symbiogenesis authored Nov 20, 2024
2 parents 344ae22 + 8e0ae56 commit 9372732
Show file tree
Hide file tree
Showing 12 changed files with 11,193 additions and 20,071 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
<WarningLevel>9999</WarningLevel>
<AnalysisLevel>latest-all</AnalysisLevel>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation>
<NoWarn>$(NoWarn);CA2007;CS1591;NU1605;SA1101;SA1124;SA1309;SA1600;SA1633</NoWarn>

<Configurations>Debug;Release;Test</Configurations>
<MauiVersion>8.0.92</MauiVersion>
<MauiVersion>9.0.10</MauiVersion>

<!-- Generate the lock file -->
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
Expand Down
7 changes: 5 additions & 2 deletions Maui.DataGrid.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Maui.DataGrid.Sample;

using Microsoft.Maui;
using Microsoft.Maui.Controls;

#pragma warning disable CA1724, CA1515

/// <summary>
Expand All @@ -11,7 +14,7 @@ public partial class App
public App()
{
InitializeComponent();

MainPage = new AppShell();
}

protected override Window CreateWindow(IActivationState? activationState) => new(new AppShell());
}
7 changes: 4 additions & 3 deletions Maui.DataGrid.Sample/Maui.DataGrid.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.22621.0</TargetFrameworks>
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.26100.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
Expand Down Expand Up @@ -31,6 +31,7 @@
<Title>Maui DataGrid Example</Title>
<AssemblyName></AssemblyName>
<Authors>Ebubekir Akgul</Authors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -83,7 +84,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="9.1.0" />
<PackageReference Include="CommunityToolkit.Maui" Version="9.1.1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Shiny.Xunit.Runners.Maui" Version="1.0.0" />
<PackageReference Include="xunit" Version="2.9.2" />
Expand Down
30,836 changes: 10,871 additions & 19,965 deletions Maui.DataGrid.Sample/packages.lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Maui.DataGrid/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
Expand Down
18 changes: 10 additions & 8 deletions Maui.DataGrid/DataGrid.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,13 @@ public partial class DataGrid

private readonly SortedSet<int> _pageSizeList = new(DefaultPageSizeSet);

#if NET9_0
private readonly Lock _reloadLock = new();
private readonly Lock _sortAndPaginateLock = new();
#else
private readonly object _reloadLock = new();
private readonly object _sortAndPaginateLock = new();
#endif
private DataGridColumn? _sortedColumn;
private HashSet<object>? _internalItemsHashSet;

Expand Down Expand Up @@ -1500,26 +1505,23 @@ private List<object> GetFilteredItems(IList<object> originalItems)
return filteredItems.ToList();
}

[UnconditionalSuppressMessage("Trimming", "IL2074", Justification = "Reflection is needed here.")]
private bool FilterItem(object item, DataGridColumn column)
{
try
{
var isItemTypeCached = _cachedType != null;

if (!isItemTypeCached)
{
_cachedType = item.GetType();
}
_cachedType ??= item.GetType();

var type = _cachedType ?? item.GetType();
var property = type?.GetProperty(column.PropertyName);
var property = _cachedType.GetProperty(column.PropertyName);

if (property?.PropertyType == typeof(object))
if (property == null || property.PropertyType == typeof(object))
{
return false;
}

var value = property?.GetValue(item, null)?.ToString();
var value = property.GetValue(item, null)?.ToString();
var result = value?.Contains(column.FilterText, StringComparison.OrdinalIgnoreCase);

if (result == null && isItemTypeCached)
Expand Down
4 changes: 2 additions & 2 deletions Maui.DataGrid/DataGridCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ internal void UpdateBindings(DataGrid dataGrid)
// And the BackgroundColor constitutes the border color of the cell.
if (dataGrid.HeaderBordersVisible)
{
SetBinding(BackgroundColorProperty, new Binding(nameof(DataGrid.BorderColor), source: dataGrid));
SetBinding(PaddingProperty, new Binding(nameof(DataGrid.BorderThickness), converter: new BorderThicknessToCellPaddingConverter(), source: dataGrid));
SetBinding(BackgroundColorProperty, BindingBase.Create<DataGrid, Color>(static x => x.BorderColor, source: dataGrid));
SetBinding(PaddingProperty, BindingBase.Create<DataGrid, Thickness>(static x => x.BorderThickness, converter: new BorderThicknessToCellPaddingConverter(), source: dataGrid));
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion Maui.DataGrid/DataGridColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public DataGridColumn()

FilterTextboxContainer = new ContentView();

FilterTextbox.SetBinding(Entry.TextProperty, new Binding(nameof(FilterText), BindingMode.TwoWay, source: this));
FilterTextbox.SetBinding(Entry.TextProperty, BindingBase.Create<DataGridColumn, string>(static x => x.FilterText, BindingMode.TwoWay, source: this));
}

#region Events
Expand Down Expand Up @@ -478,6 +478,7 @@ public bool IsSortable()
return _isSortable ??= false;
}

[UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Reflection is needed here.")]
[UnconditionalSuppressMessage("Trimming", "IL2062", Justification = "Reflection is needed here.")]
internal void InitializeDataType()
{
Expand Down
2 changes: 1 addition & 1 deletion Maui.DataGrid/DataGridHeaderRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected override void OnParentSet()
column.VisibilityChanged += OnVisibilityChanged;
}

SetBinding(BackgroundColorProperty, new Binding(nameof(DataGrid.BorderColor), source: DataGrid));
SetBinding(BackgroundColorProperty, BindingBase.Create<DataGrid, Color>(static x => x.BorderColor, source: DataGrid));
}
}

Expand Down
19 changes: 11 additions & 8 deletions Maui.DataGrid/DataGridRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected override void OnParentSet()
column.VisibilityChanged += OnVisibilityChanged;
}

SetBinding(BackgroundColorProperty, new Binding(nameof(DataGrid.BorderColor), source: DataGrid));
SetBinding(BackgroundColorProperty, BindingBase.Create<DataGrid, Color>(static x => x.BorderColor, source: DataGrid));
}
}

Expand Down Expand Up @@ -280,7 +280,7 @@ private View CreateViewCell(DataGridColumn col)

if (!string.IsNullOrWhiteSpace(col.PropertyName))
{
Binding binding = new(col.PropertyName, source: BindingContext);
var binding = CreateBindingViaReflection(col);
cell.SetBinding(BindingContextProperty, binding);
}
}
Expand All @@ -298,7 +298,7 @@ private View CreateViewCell(DataGridColumn col)

if (!string.IsNullOrWhiteSpace(col.PropertyName))
{
Binding binding = new(col.PropertyName, stringFormat: col.StringFormat, source: BindingContext);
var binding = CreateBindingViaReflection(col);
cell.SetBinding(Label.TextProperty, binding);
}
}
Expand Down Expand Up @@ -347,7 +347,7 @@ private View CreateDefaultEditCell(DataGridColumn col)

if (!string.IsNullOrWhiteSpace(col.PropertyName))
{
Binding binding = new(col.PropertyName, source: BindingContext);
var binding = CreateBindingViaReflection(col);
cell.SetBinding(BindingContextProperty, binding);
}

Expand All @@ -367,7 +367,7 @@ private Entry GenerateTextEditCell(DataGridColumn col)

if (!string.IsNullOrWhiteSpace(col.PropertyName))
{
Binding binding = new(col.PropertyName, BindingMode.TwoWay, stringFormat: col.StringFormat, source: BindingContext);
var binding = CreateBindingViaReflection(col);
entry.SetBinding(Entry.TextProperty, binding);
}

Expand All @@ -384,7 +384,7 @@ private CheckBox GenerateBooleanEditCell(DataGridColumn col)

if (!string.IsNullOrWhiteSpace(col.PropertyName))
{
Binding binding = new(col.PropertyName, BindingMode.TwoWay, source: BindingContext);
var binding = CreateBindingViaReflection(col);
checkBox.SetBinding(CheckBox.IsCheckedProperty, binding);
}

Expand Down Expand Up @@ -413,7 +413,7 @@ private Entry GenerateNumericEditCell(DataGridColumn col, Func<string, bool> num

if (!string.IsNullOrWhiteSpace(col.PropertyName))
{
Binding binding = new(col.PropertyName, BindingMode.TwoWay, source: BindingContext);
var binding = CreateBindingViaReflection(col);
entry.SetBinding(Entry.TextProperty, binding);
}

Expand All @@ -429,13 +429,16 @@ private DatePicker GenerateDateTimeEditCell(DataGridColumn col)

if (!string.IsNullOrWhiteSpace(col.PropertyName))
{
Binding binding = new(col.PropertyName, BindingMode.TwoWay, source: BindingContext);
var binding = CreateBindingViaReflection(col);
datePicker.SetBinding(DatePicker.DateProperty, binding);
}

return datePicker;
}

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Reflection is needed here.")]
private Binding CreateBindingViaReflection(DataGridColumn col) => new(col.PropertyName, BindingMode.TwoWay, stringFormat: col.StringFormat, source: BindingContext);

private void UpdateColors()
{
var rowIndex = DataGrid.InternalItems.IndexOf(BindingContext);
Expand Down
2 changes: 1 addition & 1 deletion Maui.DataGrid/Maui.DataGrid.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
Loading

0 comments on commit 9372732

Please sign in to comment.