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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:46:53+00:00 2026-05-16T18:46:53+00:00

In project A, i have a static class which stores data for specific types,

  • 0

In project A, i have a static class which stores data for specific types, this data is initialized in the static constructor

public static class MyStaticClass
{
    private static readonly Dictionary<Type, object> data = new Dictionary<Type, object>();

    static MyStaticClass() { /*fill data here*/ }

    public static object GetData(Type type) { return data[type]; }

    public static void SetData(Type type, object o) { data[type] = o; }
}

Project B uses project A. Project B is also a library.
In project B i want to use this class not only for types added in the static constructor, but also for types defined in B and its dependencies.

Basically somewhere in B i want to have the following code:

MyStaticClass.SetData(typeof(TypeInB), new object());
MyStaticClass.SetData(typeof(TypeInDllUsedByB), new object());

What would be the appropriate place to put this code in project B?
I project B there are several places i’d like to call GetData without having to worry if previous code has already been executed.

I thought about placing it in static TypeInB() and any other classes i’d like to use, but that won’t work for classes defined in other assemblies.

  • 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-16T18:46:53+00:00Added an answer on May 16, 2026 at 6:46 pm

    Create wrapper class in project B that will fwd calls to repository in project A. For example,

    public static class MyStaticClassInB
    {
    
        static MyStaticClassInB() { /*fill data here*/ }
    
        public static object GetData(Type type) { return MyStaticClass.GetData(type); }
    
        public static void SetData(Type type, object o) { MyStaticClass.SetData(type, o); }
    }
    

    Always use MyStaticClassInB in Project B (and not MyStaticClass). Now correct location to initialize types from B would be static constructor of this class.

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

Sidebar

Related Questions

In my testing project, I have a static class called FixtureSetup which I use
I have a static class in a shared project, which I want to extend
I have my project laid out like this: Project App1 App2 My static folder
I have a static class which contains a RoutedUICommand that I would like to
I have few public properties in App.xaml.cs which is in project A and I
I have a static class which is accessed by multiple remoting and other internal
I have a common project called common. Inside is a class called ExtensionMethods which
In my project's core library we have a very big class, which is tending
I have a complex class for configuration, which holds all the configuration data, and
I have the next static class: public static class GlobalVar { public static string

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.