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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:38:02+00:00 2026-05-22T23:38:02+00:00

I want to retrieve values from a tree stored in another system. For example:

  • 0

I want to retrieve values from a tree stored in another system. For example:

GetValue("Vehicle.Car.Ford.Focus.Engine.Oil.Color")

To avoid typing errors and invalid keys, I want to check the name at compile time by creating an object or class with the tree structure in it:

GetValue(Vehicle.Car.Ford.Focus.Engine.Oil.Color)

Is there an easy way to do this in C# without creating classes for each tree node? Can I use anonymous classes or subclasses? Should I create the code automatically?

  • 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-22T23:38:03+00:00Added an answer on May 22, 2026 at 11:38 pm

    If you want compile-time checking, you need to define your structure using compile-time constructs in some way. You could use T4 text template to automatically generate code from the tree structure.

    Possible ways I can think of:

    Nested static classes

    public static class Vehicle
    {
        public static class Car
        {
            public static class Ford
            {
                public static class Focus
                {
                    public static class Engine
                    {
                        public static class Oil
                        {
                            public static readonly string Color =
                                "Vehicle.Car.Ford.Focus.Engine.Oil.Color";
                        }
                    }
                }
            }
        }
    }
    

    Namespaces and static classes

    namespace Vehicle.Car.Ford.Focus.Engine
    {
        public static class Oil
        {
             public static readonly string Color =
                 "Vehicle.Car.Ford.Focus.Engine.Oil.Color";
        }
    }
    

    (Note that you can’t have both a class Ford in namespace Vehicle.Car and classes in a namespace Vehicle.Car.Ford.)

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

Sidebar

Related Questions

I want to retrieve k max values from each row in a numpy array.
I am using this code to retrieve the values I want from XML: IEnumerable<ForewordReview>
I am new to Python and WampServer . I want to retrieve values from
I want to retrieve multiples values from a field. the code I am using
I want to retrieve some values from my url and post them in a
i want retrieve route values from RouteTable, but it's null. can anybody help? public
hi i want to retrieve values from SQL database for xml tags using java
As the title says, i want to retrieve my Json data values from a
How do I retrieve the date values from the following array? Actually, want I
I want to retrieve values from SQLite database in my Android application. Here in

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.