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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:00:55+00:00 2026-06-13T02:00:55+00:00

I have a dictionary that contains classes. However, I have a lot of classes

  • 0

I have a dictionary that contains classes. However, I have a lot of classes to add to the dictionary and I would like to eliminate the long list of adds, because it’s starting to look messy. I was thinking of having all the data in a file and loading it to add to the dictionary, but then I realized that every time I wanted to create and add a new class, I would have to modify the file. I would prefer to have to include something in my newly created class that would automatically add it to the dictionary. I’m not even sure this is possible, so I would appreciate any help.

  • 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-13T02:00:56+00:00Added an answer on June 13, 2026 at 2:00 am

    Try to use reflection to dynamically locate all the required classes. Create an instance of Assembly where your classes are defined and try to filter them out. An example below shows how to locate all the classes whose name ends with Task.

    var assembly = Assembly.GetExecutingAssembly();
    var taskTypes = assembly.GetTypes()
                            .Where(t => t.Name.EndsWith("Task") && t.IsClass);
    
    Dictionary<string, object> instances =
        new Dictionary<string, object>(taskTypes.Count());
    
    foreach (Type classType in taskTypes)
    {
        object instance = Activator.CreateInstance(classType);
        instances.Add(classType.Name, instance);
        Console.WriteLine("Registered key {0} with object of type {1})",
                          classType.Name,
                          instance);
    }
    

    I’ve used Activator.CreateInstance method to create instances of your classes, but this might not be possible in your case depending on whether they have parameterless contructors etc.

    Another option might be to use one of the available IoC containers like autofac but I need more details on your problem before I can give a proper advice on this.

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

Sidebar

Related Questions

Basically I would like to have some dictionary that is an abstaction over legacy
If i have a resource dictionary that contains something like <RibbonTab x:Key=HomeRibbonComponent Header=test> </RibbonTab>
I have a ~600MB .DAT file that contains an italian dictionary (accented words with
Suppose I have a Collection of some kind that itself contains Collections; e.g., Dictionary(Of
I have data in a python dictionary that I'd like to store in a
I have a script which contains two classes. (I'm obviously deleting a lot of
I have an NSMutable dictionary that contains file IDs and their filename+extension in the
I have a bunch of classes that all contain a Shared ReadOnly Dictionary. If
I have a document which has been sloppily authored. It's a dictionary that contains
I have a Dictionary that contains thread Information Dictionary<String,Thread> 2FF 2IE 7CH etc what

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.