Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

mookid8000
Copy link
Contributor

MessagePack-CSharp is nice enough to simply skip serialization of properties and fields tagged with [IgnoreDataMember] and [IgnoreMember] without fuzz, which seems appropriate.

Since .NET also contains the [NonSerialized] attribute, which I believe is the oldest "dear serializer, please ignore this field"-type of serializer hint, it seems natural to also ignore these. This will in turn make migration from the old BinaryFormatter (which is deprecated and no longer exists in .NET 9) much easier, because [NonSerialized] was how it was told to skip specific fields.

This PR adds an extra case to the CreateEmittableMember method of DynamicObjectResolver, which causes fields decorated with [NonSerialized] to be ignored. It's backed up by an additional test Serialize_WithNonSerializedAttribute in DataContractTest.

Copy link
Collaborator

@AArnott AArnott left a comment

Choose a reason for hiding this comment

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

Looks great. Thank you for the PR and the test.

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.

2 participants