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 6101551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:30:44+00:00 2026-05-23T13:30:44+00:00

I have a singleton class called Manager that holds a list of object instances:

  • 0

I have a singleton class called Manager that holds a list of object instances:

static class Manager
{
    static List<Foo> Foos = new List<Foo>();
}

I then have a collection of object instances using a class called Meter that uses references to items in the list Foos:

class Meter
{
    public Foo MyFoo = null;
}

...

public void CreateMeter(int UserChoice)
{
    Meter MyMeter = new Meter();
    MyMeter.MyFoo = Manager.Foos[UserChoice];
}

When the application saves a project file it serializes the instances of Foo in Foos along with all the instances of Meter.

My problem is how to deserialize this arrangement. Currently I do the following:

  • Deserialize the project-wide instances of Foo to reconstruct Manager.Foos
  • Deserialize a meter instance which includes an instance of Foo for the MyFoo property
  • Search Manager.Foos and find the matching reference for MyMeter.MyFoo and then assign the reference from Manager.Foos.

This seems to me clunky and not too easy to extend. I would rather that the Meter factory doesn’t need to search Manager.Foos during deserialization because in future Meter might take it’s refence to a Foo instance from other places, not just Manager.

Is there a simple but flexible alternative solution to this deserialization problem where references to objects can be easily reconstructed?

  • 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-23T13:30:44+00:00Added an answer on May 23, 2026 at 1:30 pm

    Thanks Marc and everyone else for the suggestions. Based on Marc’s key idea and Henk’s object id generator here is what I have so far.

    Foo defines a Guid property which contains a unique Guid. This is generated in the constructor but can also be saved/restored with serialization/deserialization.

    class Foo
    {
        public Guid TheGuid = Guid.NewGuid();
    }
    

    Meter no longer uses a reference, instead it uses a Guid:

    class Meter
    {
        public Guid FooGuid;
    }
    

    When a meter is created the Guid establishes the connection:

    public void CreateMeter(int UserChoice)
    {
        Meter MyMeter = new Meter();
        MyMeter.FooGuid = Manager.Foos[UserChoice].TheGuid;
    }
    

    When Meter is serialized/deserialized the Guid is stored/loaded.

    One downside is when the Foo instance associated with a meter needs to be accessed. Instead of directly using the reference a lookup has to be performed which will incur a performance hit:

    class Manager
    {
        public List<Foo> Foos = new List<Foo>();
    
        public Foo GetFooFromGuid(Guid SearchGuid)
        {
            // search Foos and return instance with Guid == SearchGuid
        }
    }
    

    A benefit of this approach is that now I can create a delegate and have multiple sources of Foo to associate with meters:

    Func<Guid, Foo> FooSource;
    
    FooSource ManagerFooSource = Manager.GetFooFromGuid;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The goal is to have a singleton data controller class called FetchData.h/.m that pulls
i have singleton class , when calling one of the singleton methods more then
I have a specific class in my project that used for load and hold
In our unit tests where it first load db setting from a singleton class,
I am using a shared instance of a singleton class in a function, do
I have a problem using Gin. Here is a simple example. @GinModules(AppModule.class) public interface
I have an application in java that uses two different threads.And for sharing data
If a singleton implements IDisposable, what is the right way of disposing and re-creating
A bit of an architectural question... I originally created a Javascript singleton to house
I have a question concerning dependency injection. I have been keeping it simple so

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.