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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:32:09+00:00 2026-06-13T22:32:09+00:00

I want to be able to loop through a Class Property that references its

  • 0

I want to be able to loop through a Class Property that references its own properties. Why you may ask? Because it’s easier to manage later on if I want to add more properties to that Class.

Let me explain more:

public interface IElementBox
{
    string Filename { get; }
    string FileDefinition { get; set; }
    void ExtractFromFile(string stringData);
}

public abstract class Element
{
    public Element(string stringData)
    {
        this.DefFromFile(stringData);
    }
    public string Name { get; set; }
    protected abstract void DefFromFile(string stringData);
}

public class Solid : Element
{
    public Solid(string stringData) : base(stringData) { }
    public string SolidSpecificProperty { get; set; }
    protected override void DefFromFile(string stringData)
    {
        // Assign SolidSpecificProperty from string
    }
}

public class Liquid : Element
{
    public Liquid(string stringData) : base(stringData) { }
    public string LiquidSpecificProperty { get; set; }
    protected override void DefFromFile(string stringData)
    {
        // Assign LiquidSpecificProperty from string
    }
}

public class Gas : Element
{
    public Gas(string stringData) : base(stringData) { }
    public string GasSpecificProperty { get; set; }
    protected override void DefFromFile(string stringData)
    {
        // Assign GasSpecificProperty from string
    }
}

public abstract class ElementBox<T> : IElementBox where T : Element
{
    public List<T> Elements { get; set; }
    public List<T> GetElementsFromName(string name)
    {
        return this.Elements.FindAll(x => x.Name == name);
    }
    public abstract string Filename { get; }
    public string FileDefinition { get; set; }
    public abstract void ExtractFromFile(string filename);
}

public class SolidBox : ElementBox<Solid>
{
    public override string Filename
    {
        get { return "Solid.txt"; }
    }
    public override void ExtractFromFile(string stringData)
    {
        this.Elements.Add(new Solid(stringData));
    }
}

public class LiquidBox : ElementBox<Liquid>
{
    public override string Filename
    {
        get { return "Liquid.txt"; }
    }
    public override void ExtractFromFile(string stringData)
    {
        this.Elements.Add(new Liquid(stringData));
    }
}

public class GasBox : ElementBox<Gas>
{
    public override string Filename
    {
        get { return "Gas.txt"; }
    }
    public override void ExtractFromFile(string stringData)
    {
        this.Elements.Add(new Gas(stringData));
    }
}

public static class DataDefinition
{
    public static SolidBox SolidBox { get; set; }
    public static LiquidBox LiquidBox { get; set; }
    public static GasBox GasBox { get; set; }

    public static IElementBox[] ElementBoxes = new IElementBox[] { DataDefinition.SolidBox, DataDefinition.LiquidBox, DataDefinition.GasBox };
}

public static class Loader
{
    public static void LoadInfo()
    {
        for (int elementBoxNb = 0; elementBoxNb < DataDefinition.ElementBoxes.Length; elementBoxNb++)
        {
            string dataFilepath = DataDefinition.ElementBoxes[elementBoxNb].Filename;
            System.IO.StreamReader sr = System.IO.File.OpenText(dataFilepath);
            DataDefinition.ElementBoxes[elementBoxNb].ExtractFromFile(sr.ReadToEnd());
        }
    }
}

The whole purpose of this structure is to be able to define all the object properties in a text file. So that all the SolidBox.Elements objects are dynamically assigned from that text file definition.

My questions are as follow:

  • Will the property array in DataDefinition be referenced by value. Which would mean that all my data assignation would get absorbed in the void?

  • If yes (or no..), is their a better way of doing the whole thing / What would be the best way to do it?

I’ve been working on that data structure for a while now I’m getting proud of what I could achieve. I would be sad if all that was done for nothing. Although, if one if you can provide me with a better/optimal way of doing the whole thing, I will be grateful and throw my code in my archive folder.

Also, keep in mind that this is an example of the data structure. It does not reflect exactly what my code looks like and is made so to ease comprehension and reading.

Don’t hesitate to ask questions if more information is needed.

  • 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-06-13T22:32:10+00:00Added an answer on June 13, 2026 at 10:32 pm

    Deserialization (reading objects in from a persistent medium) has been solved a zillion different ways. Try using Data Contracts, like this answer demonstrates. You just need to add a few attributes to your properties to indicate what you want serialized and then it does just about all of the work for you.

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

Sidebar

Related Questions

I want to be able to take an image that i have already captured
So I have a class that is a generic and it may need to,
Im bulding a class that has a bunch of properties, and looks something like
I have multiple model methods and I want to loop and execute through each
I want to be able to change all the anchor's properties on a page.
I'm using LaTeX and BibTeX for an article, and I want to able to
Want to be able to provide a search interface for a collection of objects
I want to be able to replicate only the folder structure (not the contents)
I want to be able to do the following actions with a form submit
I want to be able to hide a selector if it contains any data.

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.