Adding new strongly typed methods to Clipboard, DataObject and IDataObject.#11545
Adding new strongly typed methods to Clipboard, DataObject and IDataObject.#11545Tanya-Solyanik merged 9 commits intodotnet:mainfrom
Conversation
e246a67 to
a89070f
Compare
...ndows.Forms/src/System/Windows/Forms/BinaryFormat/WinFormsBinaryFormattedObjectExtensions.cs
Outdated
Show resolved
Hide resolved
...ndows.Forms/src/System/Windows/Forms/BinaryFormat/WinFormsBinaryFormattedObjectExtensions.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/Clipboard.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/ComposedBinder.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/ComposedBinder.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/ComposedBinder.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/Clipboard.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/Clipboard.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
816f4c9 to
7cc2fdc
Compare
JeremyKuhne
left a comment
There was a problem hiding this comment.
Added some more comments. I'm a little concerned that we're using TypeName where it isn't necessary in some cases. We should optimize this before we fully validate this as changing it afterwords would be risky.
I still need to spend more time reviewing.
src/System.Windows.Forms/src/System/Windows/Forms/BinaryFormat/WinFormsArrayRecordExtensions.cs
Outdated
Show resolved
Hide resolved
...ndows.Forms/src/System/Windows/Forms/BinaryFormat/WinFormsBinaryFormattedObjectExtensions.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/ComposedBinder.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/ComposedBinder.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
.../System/Windows/Forms/OLE/DataObject.ComposedDataObject.NativeDataObjectToWinFormsAdapter.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/IDataObject.cs
Outdated
Show resolved
Hide resolved
b670471 to
c1e4bcd
Compare
JeremyKuhne
left a comment
There was a problem hiding this comment.
We should not be falling into the default interface implementations for our own types that derive from IDataObject.
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/IDataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11545 +/- ##
====================================================
+ Coverage 75.91821% 97.03763% +21.11941%
====================================================
Files 3164 1182 -1982
Lines 636813 354547 -282266
Branches 47008 5410 -41598
====================================================
- Hits 483457 344044 -139413
+ Misses 149901 9711 -140190
+ Partials 3455 792 -2663
Flags with carried forward coverage won't be shown. Click here to find out more. |
7903b3c to
9f06188
Compare
src/System.Windows.Forms/src/System/Windows/Forms/OLE/ITypedDataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/ITypedDataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/ITypedDataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/ITypedDataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/ITypedDataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
...System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.Composition.TypeNameComparer.cs
Outdated
Show resolved
Hide resolved
| return Matches(x, y); | ||
| } | ||
|
|
||
| public int GetHashCode(TypeName obj) |
There was a problem hiding this comment.
Where did this come from? If the code is trying to avoid allocating the full name string, ok, but it should probably use HashCode.Combine().
There was a problem hiding this comment.
I can't use the full name as an identity because it could contain assembly name in constructed types, for example, that might be type-forwarded to another assembly.
There was a problem hiding this comment.
Where did this come from? - I didn't find anything in the runtime.. Do you have suggestions where to search?
There was a problem hiding this comment.
I can't use HashCode.Combine as it does not call this GetHashCode method recursively, most of these values are TypeNames and should have their assembly names removed.
| // This is needed to resolve fields of the requested type T when using deserializers. | ||
| private readonly Dictionary<string, Type> _mscorlibTypeCache = new() | ||
| { | ||
| { "System.Byte", typeof(byte) }, |
There was a problem hiding this comment.
Because then you are comparing the right components- it is the whole point of TypeName. String comparison is fraught with errors.
4a6917d to
b7a8ed8
Compare
adamsitnik
left a comment
There was a problem hiding this comment.
I provided the answers to all the questions, please feel free to tag me again.
src/System.Windows.Forms/src/System/Windows/Forms/OLE/Clipboard.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/Internal/TypeExtensions.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/Clipboard.cs
Outdated
Show resolved
Hide resolved
...m.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.Composition.BinaryFormatUtilities.cs
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.DataStore.cs
Outdated
Show resolved
Hide resolved
|
|
||
| namespace System.Windows.Forms; | ||
|
|
||
| public interface ITypedDataObject |
There was a problem hiding this comment.
Is there a resolution to this thread? It still seems our guidance is that both should be implemented.
...ows.Forms/tests/UnitTests/System/Windows/Forms/BinaryFormatUtilitiesTests.FullCompatScope.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DragDropHelperTests.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/NativeToWinFormsAdapterTests.cs
Outdated
Show resolved
Hide resolved
...Windows.Forms/src/System/Windows/Forms/OLE/DataObject.Composition.NativeToWinFormsAdapter.cs
Show resolved
Hide resolved
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/NativeToWinFormsAdapterTests.cs
Show resolved
Hide resolved
… for example when the OOB Formatters assembly is not referenced of enabled.
…riting data to it
…re, string interpolation in test file; simplify code to read forwarded from attribute
generate TYpeName taking into account what assembly the type was forwarded from
src/System.Windows.Forms/src/System/Windows/Forms/Internal/TypeExtensions.cs
Show resolved
Hide resolved
|
|
||
| if (dataObject is not ITypedDataObject typedDataObject) | ||
| { | ||
| // TODO (TanyaSo): localize string |
There was a problem hiding this comment.
Assuming this will be done in follow up PR?
Related to ##12362
Fixes #11350
The
TryGetDatamethods use NRBF deserializer by default and will fall back to use BinaryFormatter if the application opts into BinaryFormatter use in this context.The
GetDatamethods have a compatibility mode when the appropriate AppContext switches are enabled but by default they can read only known and primitive types or POCOs with primitive fields. These methods in theDataObject class are obsoleted.Microsoft Reviewers: Open in CodeFlow