Add GetData<T> Method to Clipboard #11350
Labels
api-suggestion
(1) Early API idea and discussion, it is NOT ready for implementation
area-Clipboard
Issues related to Clipboard
area-ILLinker/AOT
tenet-performance
Improve performance, flag performance regressions across core releases
Milestone
Currently when grabbing items off the clipboard via Clipboard.GetData we give back type
object
. It would be good to add typed methods to allow users to express that they are expecting a specific type from the clipboard. This allows us to prevent giving users objects that they do not intend to receive. This will also allow us to avoid fallback to BinaryFormatter when it is not necessary since we would've checked if the requested type matches the root record and avoid the fallback if there is no match.Note that there are some slightly more specific Clipboard.GetX methods such as GetImage() and GetAudioStream() which internally calls
GetData
. We would want to update these to call the newGetData<T>
as well.A follow up to this would be to add analyzers that notify users usings the old pattern
(SomeType)Clipboard.GetData();
to useGetData<T>()
insteadThe text was updated successfully, but these errors were encountered: