Skip to content

Implement IMobileObjectMetastate interface#4750

Merged
rockfordlhotka merged 6 commits into
mainfrom
dev/4263-metastate
Oct 24, 2025
Merged

Implement IMobileObjectMetastate interface#4750
rockfordlhotka merged 6 commits into
mainfrom
dev/4263-metastate

Conversation

@rockfordlhotka

Copy link
Copy Markdown
Member

Closes #4263

@JasonBock does this match your thoughts?

@JasonBock

JasonBock commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

If it handles round-tripping these fields and lets me get rid of this code,, then yes. Specifically, fields like _editLevelAdded, _identity, etc. Right now I generate code that uses UnsafeAccessor to help a bit with Reflection performance, and the goal of this feature would be that I wouldn't care about any of this. I could tell a BO to serialize its state and/or metastate, and it would just work.

But, the way this is implemented, there's still Reflection involved. I'm not sure that's ideal. Couldn't each BO implement IMobileObjectMetastate, which would make it such that it knows which metastate fields to roundtrip, and that would eliminate Reflection usage altogether?

Basically, IMobileObjectMetastate is fine. But I don't get why MobileObjectMetastateHelper is there, using Reflection to do the work. Seems like each stereotype should implement this and handle its fields directly.

@rockfordlhotka

Copy link
Copy Markdown
Member Author

The updated implementation is much simpler - doesn't use the StateMode property and therefore only works for serialization, not undo. By doing this it eliminates the need for reflection.

@JasonBock you don't care what is in the byte array I assume? It is JSON in this case, but you are just going to treat it like a blob I assume?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the IMobileObjectMetastate interface to provide a lightweight serialization mechanism for mobile objects. The interface allows objects to serialize their field values (metastate) to and from byte arrays, specifically excluding child object references.

Key Changes:

  • Introduces IMobileObjectMetastate interface with GetMetastate() and SetMetastate() methods
  • Implements the interface in MobileObject and MobileBindingList<T> base classes
  • Creates MobileObjectMetastateHelper for JSON-based serialization/deserialization of metastate

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
IMobileObjectMetastate.cs New interface defining metastate serialization contract
MobileObjectMetastateHelper.cs Helper class implementing JSON serialization logic for metastate
MobileObject.cs Implements IMobileObjectMetastate interface with explicit interface implementation
MobileBindingList.cs Implements IMobileObjectMetastate interface with explicit interface implementation
MobileObjectMetastateTests.cs Test coverage for metastate serialization with BrokenRule examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JasonBock

Copy link
Copy Markdown
Contributor

The updated implementation is much simpler - doesn't use the StateMode property and therefore only works for serialization, not undo. By doing this it eliminates the need for reflection.

@JasonBock you don't care what is in the byte array I assume? It is JSON in this case, but you are just going to treat it like a blob I assume?

Correct, I don't care what's in the array. I assume the implementor knows what they're doing ;)

@rockfordlhotka

Copy link
Copy Markdown
Member Author

Correct, I don't care what's in the array. I assume the implementor knows what they're doing ;)

That's just silliness!

@rockfordlhotka rockfordlhotka merged commit 482bb60 into main Oct 24, 2025
2 checks passed
@rockfordlhotka rockfordlhotka deleted the dev/4263-metastate branch October 24, 2025 20:48
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.

Add a "Metastate" Interface for BOs to Implement to Simplify Serialization

3 participants