Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6151703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:48:23+00:00 2026-05-23T19:48:23+00:00

I am using binary serialization (with BinaryFormatter, etc) to serialize a graph of objects.

  • 0

I am using binary serialization (with BinaryFormatter, etc) to serialize a graph of objects. Of those objects, some have fields of a certain type that is similar to an enumeration, except with additional properties and methods.

The problem that every time this enum-like object gets deserialized, a new instance of the type is created. Is there some sort of special deserialization method that allows you to return one of a set of existing objects, instead of creating a completely new one?

I’ve heard of ways to do this per type containing the enum-like object, but I would rather make it so that any class containing the enum-like object will automatically deserialize it by looking in the existing objects of the enum-like type.

(Why I want this, in case it matters

  1. Equality becomes easier, I can just use the default reference-comparing operators instead of having to override Equals, GetHashCode, ==, and != and implement IEquatable.

  2. Some of the data in the enum-like object may change, and I want the serialized data to update to the new data without lots of code. (Note that there is a field in the enum-like object that will never change.))

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:48:23+00:00Added an answer on May 23, 2026 at 7:48 pm

    You would do this with ISerializationSurrogate.

    See here for some example code.

    Update

    In my case, I need to re-use existing (boxed) instances for the SymbolId and bool value types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data object that is deep-cloned using a binary serialization. This data
I have data that has been stored using binary serialization for the following class:
I am performing serialization using System.Runtime.Serialization.Formatters.Binary.BinaryFormatter . I have a collection which wraps a
I have a problem using boost serialization using binary archives. It works when using
Lets say you have various objects of arbitrary type that you would like to
I'm using Binary Serialization in .NET to clone objects. Any of my own classes
I save data using binary serialization. Now I have changed a field in the
I am having an issue using BinaryFormatter.Serialize. I have this generic extension method to
I have a few objects serialized [edit: using BinaryFormatter] this way Obj_A 1 Obj_A
I have a class I serialize to a file, ie. myfile01.myfile. I'm using binary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.