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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:45:13+00:00 2026-05-22T12:45:13+00:00

I am currently working on a system for storing and retrieving data from a

  • 0

I am currently working on a system for storing and retrieving data from a master dictionary class. Imagine something like this:

public class Manager {
    Dictionary<string, Category> _categories;

    public T GetValue<T>(string category, string id){
        return _categories[category].GetValue<T>(id);
    }
}

public class Category {
    Dictionary<string, Category> _subCategories;

    // How could I approach something like this?
    Dictionary<T, Dictionary<string, IElementExample<T>> _categoryDict;

    public T GetValue<T>(string id){
        if (_categoryDict.ContainsKey(T)){
            return _categoryDict[T][id];
        }
        return default(T);
    }
    public SetValue<T>(string id, T value){
        if (_categoryDict.ContainsKey(T)){
            if (_categoryDict[T].ContainsKey(id)){
                _categoryDict[T][id] = value;
            } else {
                _categoryDict[T].Add(id, value);
            }
        } else {
            _categoryDict.Add(T, new Dictionary<string, IElementExample<T>>());
            _categoryDict[T].Add(id, value);
        }
    }
}

//
public interface IElementExample<T> {
    T Value {get;set;}
    string Id {get;set;}
    string Comment{get;set;}

    string Serialize();
    void Deserialize(string serial);
}

public class StringElement : IElementExample<string> {
    string m_value;
    string m_id;
    string m_comment;

    string Value { get { return m_value; }}
    string Id { get { return m_id; }}
    string Comment { get { return m_comment; }}

    string Serialize(){

    }
    void Deserialize(){

    }
}

The thing that is tripping me up is that obviously I can’t actually have Dictionary<T, Dictionary<string, IElementExample<T>>. Does anyone have any thoughts on how I might be able to accomplish something like that though?

The goal here is to create a master location where a lot of data can be stored (for game configuration variables), which I will then serialize/deserialize to/from XML. I have something that works for this already, and it works great, but it is impossible to add support for new data types without editing the Manager/Category classes to add support (at the moment instead of GetValue it is GetString/GetFloat/GetInt/GetBool/GetVector3… etc).

I can ensure that it only actually works with classes that are designed to work with it by adding “where” type constraint to ensure that it implements my interface. I’m just not sure how to go about setting up my “category” class in such a way that it can store and retrieve any “IExampleInterface<>” – if it is even possible.

I’d like to be able to use this for different projects that all contain the major types (string/int/float/bool…) – but also have their own custom structs and classes.

Thank you in advance for any input on this matter, I’ve been trying to figure it out on my own – but it’s getting the better of me for sure.

  • 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-22T12:45:14+00:00Added an answer on May 22, 2026 at 12:45 pm

    I didn’t work through all the code but it looks like you want a

     Dictionary<object, Dictionary<string, object> _categoryDict;
    

    or maybe a

    Dictionary<Type, Dictionary<string, object> _categoryDict;
    

    You correctly discovered that generics are not ‘dynamic’. If you want to mix different types, you will need type-casting.

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

Sidebar

Related Questions

The system I am currently working on requires some role-based security, which is well
I'm currently working on an asp.net-mvc content management system. It would be incredibly useful
I'm currently working on a project that hooks into various system calls and writes
Currently, I am working on a new version control system as part of a
I'm currently working with C++ and .NET 1.1 (Don't ask...), and I'd like to
I currently working on an issue tracker for my company to help them keep
I am currently working on a project and my goal is to locate text
I'm currently working on creating a new C# project that needs to interact with
I am currently working on a project with specific requirements. A brief overview of
I'm currently working at a small web development company, we mostly do campaign sites

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.