Skip to content

Remove reflection from UICultureUtilities#83038

Merged
jaredpar merged 1 commit intomainfrom
copilot/remove-reflection-uiculture-utilities
Apr 3, 2026
Merged

Remove reflection from UICultureUtilities#83038
jaredpar merged 1 commit intomainfrom
copilot/remove-reflection-uiculture-utilities

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

UICultureUtilities.cs used reflection to discover and invoke the CultureInfo.CurrentUICulture setter (falling back to Thread.CurrentThread.CurrentUICulture) because the setter wasn't universally available when the code was written. The API is now directly accessible in .NET Standard 2.0+.

Changes

  • Deleted TryGetCurrentUICultureSetter and TryGetCurrentThreadUICultureSetter reflection helpers, the static constructor, s_setCurrentUICulture field, and currentUICultureName constant
  • Replaced indirect s_setCurrentUICulture(value) calls with CultureInfo.CurrentUICulture = value
  • Removed the null-setter early-return guard from all three WithCurrentUICulture overloads (no longer needed since the setter is always available)
  • Dropped using System.Diagnostics.CodeAnalysis and using System.Reflection

Before:

// ~100 lines of reflection scaffolding to conditionally find and invoke the setter
private static readonly Action<CultureInfo>? s_setCurrentUICulture;
// ...
s_setCurrentUICulture(savedCulture);

After:

CultureInfo.CurrentUICulture = savedCulture;
Microsoft Reviewers: Open in CodeFlow

Copy link
Copy Markdown
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Hah nice!

@jaredpar jaredpar merged commit 2d43d45 into main Apr 3, 2026
24 checks passed
@jaredpar jaredpar deleted the copilot/remove-reflection-uiculture-utilities branch April 3, 2026 03:44
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants