-
Notifications
You must be signed in to change notification settings - Fork 971
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
Add JSON Serialization Support for OLE #11527
base: main
Are you sure you want to change the base?
Conversation
Include feature/* branches for PR builds (dotnet#11478)
merging main into the feature branch
Merge the latest main into the feature branch
Merge the latest main into the feature branch
Merge the latest from main
src/System.Windows.Forms/src/System/Windows/Forms/OLE/JsonData.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/BinaryFormat/WinFormsBinaryFormatWriter.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
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature/clipboard #11527 +/- ##
===========================================================
+ Coverage 74.74065% 74.78245% +0.04179%
===========================================================
Files 3045 3045
Lines 630626 630886 +260
Branches 46860 46874 +14
===========================================================
+ Hits 471334 471792 +458
+ Misses 155932 155724 -208
- Partials 3360 3370 +10
Flags with carried forward coverage won't be shown. Click here to find out more. |
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.
Generally looks good, some minor comments.
public static void WriteJsonData(Stream stream, IJsonData jsonData) | ||
{ | ||
using BinaryFormatWriterScope writer = new(stream); | ||
new BinaryLibrary(libraryId: 2, "System.Private.Windows.VirtualJson").Write(writer); |
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'd put this string in the JsonData type as a constant with a comment.
src/System.Windows.Forms/src/System/Windows/Forms/OLE/DataObject.cs
Outdated
Show resolved
Hide resolved
|
||
public readonly string TypeFullName => $"{typeof(JsonData<T>).FullName}"; | ||
|
||
public readonly object GetRealObject(StreamingContext context) => |
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.
While you don't technically need IObjectReference
for our usages, the workaround for Clipboard
versions that don't know of this type would be to copy this with IObjectReference
. You can comment to that effect. Writing a test to capture this behavior would be good too.
The test should use the writer code to manually write a JsonData
object to a stream, then you can read it with the deserializer and a binder that redirects to this actual type.
merge the latest into the clipboard branch
merging the latest main into clipboard feature branch
@willibrandon you might be interested in the clipboard work here. |
Merge main into feature/clipboard
… without needing to know generic type
…sonData not exist
…ot forcing preview language version which is not supported by VB Use fluent assertions in ClipboardProxyTests - copied from Loni's PR dotnet#11527 for future merging.
Enable simple creation of VB test projects in this repo solution by not forcing preview language version which is not supported by VB Use fluent assertions in ClipboardProxyTests - copied from Loni's PR #11527 for future merging.
Related: #11368
This is a start to support JSON serialization in OLE scenarios.
JsonData<T>
: This is our wrapper class that holds the JSON serialized data along with the original type information. Note that the data that is being JSON serialized uses default JsonSerializer behavior. Users can follow the remarks of the public APIs if custom JSON serialization behavior is needed.Public APIs:
DataObject.SetDataAsJson()
- Allows users to add data toDataObject
that will be JSON serialized. This is how we support JSON serialization for drag/drop scenario.Clipboard.SetDataAsJson()
- Allows users to conveniently JSON serialize a type onto the clipboard, but note that this does not acceptDataObject
being passed in. If users want to place aDataObject
on the clipboard, users should ensure data they want to be JSON serialized is already in theDataObject
by utilizingDataObject.SetDataAsJson
and then useClipboard.SetDataObject()
.Tests:
JsonData<T>
JsonData<T>
not existing in .NET 8. More investigation needs to be done here.JsonSerializer
uses reflection to serialize by default, which will not be available when trimming is turned on. We will need to either use source generator APIs to support trimming or configure JsonSerializerOptions.TypeInfoResolverMicrosoft Reviewers: Open in CodeFlow