Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
Expand Down Expand Up @@ -44,7 +44,7 @@ public class JsonLocalizationOptions : LocalizationOptions
public bool IgnoreLocalizerMissing { get; set; }

/// <summary>
/// 获得/设置 如果 Value 值为 null 时使用 Key 代替 默认 false 触发异常
/// 获得/设置 如果 Value 值为 null 时使用 Key 代替 默认 false
/// </summary>
public bool UseKeyWhenValueIsNull { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions test/UnitTest/Locales/en-US.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"BootstrapBlazor.Server.Data.Foo": {
"Name": "Name",
"DateTime": "DateTime",
Expand Down Expand Up @@ -28,6 +28,6 @@
},
"UnitTest.Utils.UtilityTest": {
"Test-Null": null,
"Test-Key:": ""
"Test-Key": ""
}
}
11 changes: 8 additions & 3 deletions test/UnitTest/Utils/UtilityTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
Expand Down Expand Up @@ -393,14 +393,19 @@ public void GetJsonStringByTypeName_UseKeyWhenValueIsNull()

var test1 = items.FirstOrDefault(i => i.Name == "Test-Null");
Assert.NotNull(test1);

#if NET9_0
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional compilation directive uses NET9_0 (exact version match) which is inconsistent with the pattern used elsewhere in the codebase. Other files use NET9_0_OR_GREATER (e.g., in CacheManager.cs, DefaultDispatchService.cs, ICacheManager.cs).

Consider using NET9_0_OR_GREATER instead for consistency and to ensure the code works correctly for future .NET 9.x patch versions.

Suggested change
#if NET9_0
#if NET9_0_OR_GREATER

Copilot uses AI. Check for mistakes.
Assert.Equal("", test1.Value);
#elif NET10_0_OR_GREATER
Assert.Equal("Test-Null", test1.Value);
#endif
Comment on lines +397 to +401
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NET10_0_OR_GREATER preprocessor symbol references .NET 10, which does not exist yet. As of January 2025 (my knowledge cutoff), .NET 9 is the latest stable release. While .NET 10 may be in preview or released by November 2025, this conditional compilation logic appears speculative.

Additionally, the test logic suggests different behavior between .NET 9 and .NET 10 for the same localization scenario (empty string vs. "Test-Null"), which seems unexpected. This conditional should be reviewed to ensure it reflects actual behavioral differences in the framework, or simplified if the behavior is actually the same across versions.

Suggested change
#if NET9_0
Assert.Equal("", test1.Value);
#elif NET10_0_OR_GREATER
Assert.Equal("Test-Null", test1.Value);
#endif
Assert.Equal("", test1.Value);

Copilot uses AI. Check for mistakes.

var test2 = items.FirstOrDefault(i => i.Name == "Test-Key");
Assert.NotNull(test2);
Assert.Equal("Test-Key", test2.Value);
Assert.Equal("", test2.Value);

option.UseKeyWhenValueIsNull = false;
items = Utility.GetJsonStringByTypeName(option, this.GetType().Assembly, "UnitTest.Utils.UtilityTest", "en-US", true);
items = Utility.GetJsonStringByTypeName(option, GetType().Assembly, "UnitTest.Utils.UtilityTest", "en-US", true);

test1 = items.FirstOrDefault(i => i.Name == "Test-Null");
Assert.NotNull(test1);
Expand Down
Loading