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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:38:10+00:00 2026-05-26T21:38:10+00:00

Consider the following example: interface IPropertyCollection { public MethodWrapper GetPropertySetterByName(string name); //<<– I want

  • 0

Consider the following example:

interface IPropertyCollection
{
    public MethodWrapper GetPropertySetterByName(string name);
    //<<-- I want the implementation from A and B merged into here somehow
}
class A : IPropertyCollection
{
    static PropertyMap properties = new PropertyMap(typeof(A));
    public MethodWrapper GetPropertySetterByName(string name)
    {
        return properties.SomeFunc(name);
    }
}
class B : IPropertyCollection
{
    static PropertyMap properties = new PropertyMap(typeof(B));
    public MethodWrapper GetPropertySetterByName(string name)
    {
        return properties.SomeFunc(name);
    }
}

I want to have a static member in each class keeping track of things in that class only and i want it to behave exactly the same for every class, but with different content. Each static member should only keep track of one single class. I want to be able to get access to the classes’ static member by just having an instance of any IPropertyCollection.

Something like this:

    IPropertyCollection a = new A();
    IPropertyCollection b = new B();
    a.GetPropertySetterByName("asdfsj");  //Should end up in static A.properties 
    b.GetPropertySetterByName("asdfsj");  //Should end up in static B.properties 

Now this will work with my example code but i don’t want to repeat all those lines inside A and B and 50 other classes.

  • 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-26T21:38:11+00:00Added an answer on May 26, 2026 at 9:38 pm

    Use a (curiously recurring) generic common base class:

    abstract class Base<T> : IPropertyCollection where T : Base<T> {
      static PropertyMap properties = new PropertyMap(typeof(T));
      public MethodWrapper GetPropertySetterByName(string name) {
          return properties.SomeFunc(name);
      }
    }
    
    class A : Base<A> { }
    class B : Base<B> { }
    

    Since the base class is generic, a different “version” of its static members will be “generated” for each different type parameter.

    Just be careful with evil dogs 🙂

    class Evil : Base<A> { } // will share A's static member...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider the following example: public interface ITask { void Execute(); } public class LoggingTaskRunner
Consider the following simple RESTEasy (JAX-RS) service: @Path(/example-service) public interface ExampleService { @Path(/ping) @GET
Consider the following example: public class Sandbox { public interface Listener<T extends JComponent> {
Consider the following example: public interface Bar { } @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public
Consider the following example. I have an interface MyInterface, and then two abstract classes
Consider the following code. public interface IFoo { } public class Bar { public
Consider following simple DAO example: public abstract class DAOFactory { public abstract AccountDAO getAccountDAO();
Consider the following very basic WCF service implementation: public enum TransactionStatus { Success =
Say for example, I have the following: public interface IPet { long? Id {

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.