- 
                Notifications
    You must be signed in to change notification settings 
- Fork 117
Narrow AdvancedCollectionView trimming warning so that it only triggers in unsafe usages #724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but I'd like explicit approval from @Sergio0694 before we merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a good way to fix this. This whole type would need to be reworked to be properly trim-safe. For instance, there's nothing enforcing that the T being used to create a sort descriptor will actually match the source type being used. Additionally annotating a T and then suppressing is not correct, the annotations should rather flow. As a rule of thumb, suppressions are almost always incorrect and should be avoided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better than before but it's not entirely safe 😅
| /// Gets the name of property to sort on | ||
| /// </summary> | ||
| public string PropertyName { get; } | ||
| public virtual string? PropertyName { get; } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change technically
| Comparer = comparer ?? ObjectComparer.Instance; | ||
| } | ||
|  | ||
|  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: extra blank line
| } | ||
|  | ||
|  | ||
| [UnconditionalSuppressMessage("Trimming", "IL2070:'this' argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The parameter of method does not have matching annotations.", | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not safe. Someone could derive from SortDescriptor, use the base constructor with no annotations, manually assign or override PropertyName to return a property, and then this would silently suppress a valid warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with this design to avoid adding a suppression in SortDescription<T>, but you're right that this opens up unsafe extensibility since the classes aren't sealed. Should I just go for the suppression in SortDescription<T>?
Fixes
Fixes #723
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Trimming warning triggers on every usage of AdvancedCollectionView
What is the new behavior?
Trimming warning only triggers when you make use of reflection-based sorting.
PR Checklist
Please check if your PR fulfills the following requirements:
Other information