-
Notifications
You must be signed in to change notification settings - Fork 458
[Property Column] Remove boxing when formatting the property. #4070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vnbaaij
merged 6 commits into
microsoft:dev
from
Tyme-Bleyaert:feat/property-column/prevent-boxing-on-fomat
Aug 28, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c265876
Remove boxing when formatting the property in property columns.
c6c5dea
remove redundant else
26682b3
resolve nitpicks
19b8c84
inlined the parameters of CreateFormat
7e39e37
Add comment to explain why double cast is necessary
41b705b
Merge branch 'dev' into feat/property-column/prevent-boxing-on-fomat
vnbaaij File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/Core/PropertyColumn/PropertyColumnFormatterTests.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| ο»Ώ@using Xunit; | ||
| @inherits TestContext | ||
| @code | ||
| { | ||
| [Fact] | ||
| public void PropertyGrid_Should_Format_ValueTypes() | ||
| { | ||
| var cut = Render( | ||
| @<FluentDataGrid Items="@People" TGridItem="Person"> | ||
| <PropertyColumn Property="@(p => p.PersonId)" Format="D4" /> | ||
| </FluentDataGrid> | ||
| ); | ||
|
|
||
| var firstCellText = cut.Find("td").TextContent; | ||
| Assert.Equal("0001", firstCellText); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void PropertyGrid_Should_Format_NullableValueTypes() | ||
| { | ||
| var cut = Render( | ||
| @<FluentDataGrid Items="@People" TGridItem="Person"> | ||
| <PropertyColumn Property="@(p => p.BirthDate)" Format="m" /> | ||
| </FluentDataGrid> | ||
| ); | ||
|
|
||
| var firstCellText = cut.Find("td").TextContent; | ||
| Assert.Equal(_people[0].BirthDate!.Value.ToString("m"), firstCellText); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void PropertyGrid_Should_Format_ReferenceTypes() | ||
| { | ||
| var cut = Render( | ||
| @<FluentDataGrid Items="@People" TGridItem="Person"> | ||
| <PropertyColumn Property="@(p => p.Name)" Format="{0} test" /> | ||
| </FluentDataGrid> | ||
| ); | ||
|
|
||
| var firstCellText = cut.Find("td").TextContent; | ||
| Assert.Equal(string.Format("{0} test", _people[0].Name), firstCellText); | ||
| } | ||
|
|
||
|
|
||
| [Fact] | ||
| public void PropertyGrid_Should_Throw_When_FormatUsedOnNonFormattableProperty() | ||
| { | ||
| Assert.Throws<InvalidOperationException>(() => Render( | ||
| @<FluentDataGrid Items="@People" TGridItem="Person"> | ||
| <PropertyColumn Property="@(p => p.NickName)" Format="{0} test" /> | ||
| </FluentDataGrid> | ||
| )); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
41 changes: 41 additions & 0 deletions
41
tests/Core/PropertyColumn/PropertyColumnFormatterTests.razor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // ------------------------------------------------------------------------ | ||
| // This file is licensed to you under the MIT License. | ||
| // ------------------------------------------------------------------------ | ||
|
|
||
| using Bunit; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Microsoft.FluentUI.AspNetCore.Components.Tests.PropertyColumn; | ||
| public partial class PropertyColumnFormatterTests | ||
| { | ||
| private protected record Person(int PersonId, CustomFormattable Name, DateOnly? BirthDate, string NickName) | ||
| { | ||
| public bool Selected { get; set; } | ||
| }; | ||
|
|
||
| private protected class CustomFormattable : IFormattable | ||
| { | ||
| private readonly string _value; | ||
| public CustomFormattable(string value) => _value = value; | ||
| public string ToString(string? format, IFormatProvider? provider) => | ||
| string.IsNullOrEmpty(format) ? _value : string.Format(format, _value); | ||
| } | ||
|
|
||
| private readonly IList<Person> _people = | ||
| [ | ||
| new Person(1, new("Jean Martin"), new DateOnly(1985, 3, 16), string.Empty), | ||
| new Person(2, new("Kenji Sato"), new DateOnly(2004, 1, 9), string.Empty), | ||
| new Person(3, new("Julie Smith"), new DateOnly(1958, 10, 10), string.Empty), | ||
| ]; | ||
|
|
||
| private protected IQueryable<Person> People => _people.AsQueryable(); | ||
|
|
||
| public PropertyColumnFormatterTests() | ||
| { | ||
| JSInterop.Mode = JSRuntimeMode.Loose; | ||
| Services.AddSingleton(LibraryConfiguration.ForUnitTests); | ||
|
|
||
| var keycodeService = new KeyCodeService(); | ||
| Services.AddScoped<IKeyCodeService>(factory => keycodeService); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.