Skip to content

Changed the serialization method for copy/paste operations in the dra…#312

Open
davidebazzi wants to merge 1 commit into
masterfrom
311-copypaste-object-serialization
Open

Changed the serialization method for copy/paste operations in the dra…#312
davidebazzi wants to merge 1 commit into
masterfrom
311-copypaste-object-serialization

Conversation

@davidebazzi
Copy link
Copy Markdown
Collaborator

…wing, from the old BinaryFormatter to JsonSerialize.

…wing, from the old BinaryFormatter to JsonSerialize.
@davidebazzi davidebazzi linked an issue May 20, 2026 that may be closed by this pull request

#region IUIService implementation
public override IUIService UIService => this;
GeoObjectList IUIService.GetDataPresent(object data)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to adjust this function as well. It still seems to rely on BinaryFormatter.

@@ -291,22 +291,29 @@
}
void IUIService.SetClipboardData(GeoObjectList objects, bool copy)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation has a few issues that could lead to resource leaks and unhandled exceptions:
Problems:

  1. MemoryStream is only disposed if no exception occurs—use using statement
  2. No error handling for serialization or clipboard operations
  3. Missing null validation for objects parameter

return objects;
}
bool IUIService.HasClipboardData(Type typeOfdata)
bool IUIService.HasClipboardData()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation unnecessarily deserializes the entire clipboard data just to check if it exists:

  1. Performance: Deserializes full object graph just to return a boolean
  2. No error handling: Will throw if clipboard access fails or deserialization errors occur

@dsn27
Copy link
Copy Markdown
Collaborator

dsn27 commented May 21, 2026

Hi @davidebazzi ,

Thank you for your effort on migrating the clipboard operations from binary serialization to JSON! This is an important step toward modernizing the codebase.
The overall approach looks great. Using JsonSerialize for clipboard operations is exactly the right direction. However, I've identified a few small improvements needed before we can merge this PR.

I've added detailed review comments on each line with suggested code fixes.
Once these minor adjustments are made, we're good to merge! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy/Paste object serialization

2 participants