Use more trim-friendly patterns for Type.DefaultBinder and CultureData#119226
Use more trim-friendly patterns for Type.DefaultBinder and CultureData#119226jkotas merged 7 commits intodotnet:mainfrom
Conversation
|
This should realize the small improvement from #119171 by changing the source code. |
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs
Show resolved
Hide resolved
|
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
There was a problem hiding this comment.
Pull Request Overview
This PR modernizes type initialization patterns and improves thread safety in reflection-related code. The changes focus on using more trim-friendly patterns for Type.DefaultBinder and CultureData, replacing outdated collection initialization syntax with modern C# collection expressions.
- Replaces
Type.EmptyTypesreferences with modern collection expression syntax[] - Modernizes
Type.DefaultBinderimplementation to use singleton pattern instead of lazy initialization with locks - Improves thread safety in
CultureDatacaching by usingInterlocked.CompareExchangepattern
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Type.cs | Updates DefaultBinder to use singleton pattern and replaces EmptyTypes with [] |
| src/libraries/System.Private.CoreLib/src/System/DefaultBinder.cs | Implements singleton Instance property and updates Missing.Value references |
| src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs | Improves thread safety using Interlocked.CompareExchange pattern |
| Multiple reflection files | Replace Type.EmptyTypes with modern collection expression [] |
| src/coreclr files | Updates native AOT and CoreCLR implementations to use modern patterns |
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Outdated
Show resolved
Hide resolved
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs
Show resolved
Hide resolved
|
The main improvement is realized by avoiding dependencies on System.Type public static fields. System.Type exposes static fields in the public surface and so referencing one of the fields will bring all of them into the dependency graph via the static constructor. |
…CultureData.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.