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

  • Home
  • SEARCH
  • 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 5935235
In Process

The Archive Base Latest Questions

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

I have an interface: interface IInterface { string Name { get; } } that

  • 0

I have an interface:

interface IInterface 
{
    string Name { get; }
}

that is implemented by an generic abstract class:

public class BInterface<T> : IInterface
{
    static BInterface() 
    { 
        // Or anything that would be implementation class specific
        Name = typeof(BInterface<>).GetType().Name;  
    }
    public static string Name { get; private set; }
    string IInterface.Name { get { return Name; } }
}

Which is in turn implemented in a concrete class:

public class CInterface : BInterface<int> 
{
}

I know how to get the references to the concrete classes via ‘type.IsAssignableFrom’, ‘!type.IsInterface’ and ‘!type.IsAbstract’, but that is as far as I have managed.

I need to get, via Reflection, the VALUE of the static Name property for any of the concrete classes. However, for the life of my poor brain, I cannot figure the code to accomplish this. Any hints would be great.

EDIT (In clarification):

I am aware that the static property needs to read from the base class. However….

The static field will contain the base name of the concrete class –> derived via reflection in the static constructor of the base class. This works (and I know how to accomplish it) as we do it all over the place.

I this case, I am attempting to build a factory class that needs to know this static field, and needs to get to it via Reflection due to the some (other) requirements of the factory implementation.

EDIT (again) Expanded code:

Here is a nearly complete, if useless, example of what I am attempting to accomplish.

    public interface IInterface
    {
        string Name { get; }
        object Value { get; set; }
    }

    public class BInterface<T> : IInterface
    {
        static BInterface()
        {
            // Or anything that would be implementation class specific
            Name = typeof(BInterface<>).GetType().Name; // Should be CInterface, DInterface depending on which class it is called from.
        }

    string IInterface.Name { get { return Name; } }
    object IInterface.Value { get { return Value; } set { Value = (T)value; } }

    public static string Name { get; private set; }
    public T Value { get; set; }
}

public class CInterface : BInterface<int>
{
}

public class DInterface : BInterface<double>
{
}

public static class InterfaceFactory
{
    private readonly static IDictionary<string, Type> InterfaceClasses;

    static InterfaceFactory()
    {
        InterfaceClasses = new Dictionary<string, Type>();

        var assembly = Assembly.GetExecutingAssembly();
        var interfaceTypes = assembly.GetTypes()
                                     .Where( type => type.IsAssignableFrom(typeof (IInterface)) 
                                         && !type.IsInterface 
                                         && !type.IsAbstract);
        foreach (var type in interfaceTypes)
        {
            // Get name somehow
            var name = "...";
            InterfaceClasses.Add(name, type);
        }
    }

    public static IInterface Create(string key, object value, params object[] parameters)
    {
        if (InterfaceClasses.ContainsKey(key))
        {
            var instance = (IInterface) Activator.CreateInstance(InterfaceClasses[key], parameters);
            instance.Value = value;

            return instance;
        }
        return null;
    }
}

The part in the static constructor of the IntefaceFactory inside the foreach loop is what I am attempting to solve. Hopefully, this is clearer.

  • 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-22T15:13:32+00:00Added an answer on May 22, 2026 at 3:13 pm

    This is how to get static property of concrete class from the instance:

    var staticProperty = instance.GetType()
        .GetProperty("<PropertyName>", BindingFlags.Public | BindingFlags.Static);
    var value = staticProperty.GetValue(instance, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a generic list class that implements a particular interface. The list items
Have a interface class abc { public: virtual int foo() = 0; ... }
Currently I have my VaryByCustom functionality implemented in classes that implement an interface IOutputCacheVaryByCustom
If i have the following entity: public class PocoWithDates { public string PocoName {
I have an object that implements two interfaces... The interfaces are: public interface IObject
I have following Classes and interfaces.. public interface ITaggable { ICollection<Tag> Tags { get;
If i have an interface: interface IFoo { int Offset {get;} } can i
Suppose I have this interface public interface IFoo { ///<summary> /// Foo method ///</summary>
So lets say I have this interface: public interface IBox { public void setSize(int
If I have interface IFoo, and have several classes that implement it, what is

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.