[MilCodeGen] Declare Equals/GetHashCode and property getters for fields as readonly #10618
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.
Description
Modifies MilCodeGen to generate
readonly
getters for fields whereSkipProperties="false"
, in case the properties are skipped (SkipProperties="true"
) they live in the non-generated area and thus were modified manually.Equals
override uses new syntax and isreadonly
.Equals
is nowreadonly
.GetHashCode
isreadonly
and all the supporting props (IsEmpty
,IsDistinguishedIdentity
) arereadonly
to prevent copies in the particular call chain.Rest of the members that were not in the impact zone are left untouched and shall be done separately in subsequent PRs.
Customer Impact
Increased performance/better codegen.
Regression
No.
Testing
Local build, most of the generated structs have unit tests already including
Equals
/GetHashCode
checks.Risk
Low. The point to consider is whether we could make any of the members that are to become
readonly
mutate the struct in the future, for me that answer is no.Equals
/GetHashCode
should never modify the state, even on mutable structs.Microsoft Reviewers: Open in CodeFlow