Repository navigation
Write enum values by name, from the assembly that declares the enum - #108
Merged
Merged
Conversation
A default, a constant or an attribute argument of an enum type was written as a cast of its number, (ApiSplit)0, and an attribute's enum from another assembly was decoded as if it were an int. The reader now finds the enum, in the assembly being read, its folder, the folders ApiReaderOptions adds, or the installed .NET runtime, following type forwarders such as System.Runtime's: ApiSplit.None, StringComparison.Ordinal, FileShare.Read | FileShare.Delete for flags, and the real underlying type for decoding, so [Sized(Size.Large)] on a byte enum reads right. An enum that cannot be found, or a value with no member, stays a cast. The comparison counts a cast and a name of the same enum as the same value, since one machine can find an enum that another cannot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes two of the known gaps:
(ApiSplit)0.int. That garbled any argument whose enum wasn't anint.What changes
The reader now finds the enum in the assembly that declares it. It looks in this order:
ApiReaderOptions.ReferenceDirectoriesadds;It follows type forwarders along the way, such as
System.Runtime's toSystem.Private.CoreLib. The result, from the newenumssample:|.(Access)64, or an enum that can't be found, stays a cast.ApiReaderOptions { SearchRuntime = false }turns off the runtime lookup.(Access)64toAccess.Readisn't reported either.api/gains the new publicApiReaderOptionsand its twoReadoverloads. The change is additive.Cost
Referenced assemblies are opened only when an enum needs them, and only their metadata is read. The assembly being read is indexed once; the others are searched in place. Reading CoreLib is unchanged at 107 MB. System.Collections.Immutable allocates 3.2 MB (it was 3.7) and takes about 4.5 ms, up from 1.8 ms, because it now opens System.Runtime and CoreLib's metadata. That's a fixed cost of a few milliseconds per read.
Tests
enumssample; a test that an enum that can't be found stays a cast; and a test that a name and a cast compare as no change. Taking out that comparison rule fails the test.mise run cipasses: 88 library tests and 630 tool tests.Not done: in solution mode, the tool could also look in the folders of a project's NuGet dependencies. Today an enum that comes from a package stays a cast unless its assembly sits next to the build.
🤖 Generated with Claude Code