jeudi 2 juin 2022

How to get static properties from base type via reflection

I try to get static properties from a base type via reflection. There are many questions regarding this topic on this side, but they all focus on getting non static properties of a base type or static properties from the target type.

public class A
{
    public static string STATIC_BaseProp => "STATIC_BaseProp"; //<-- I want this
    public string BaseProp => "BaseProp";
}

public class B : A
{
    public static string STATIC_Prop => "STATIC_Prop";
    public string Prop => "PROP";
}

static void Main(string[] args)
{
    var type = typeof(B);
    foreach (var propertyInfo in type.GetProperties())
    {
        Console.log(propertyInfo);
    }
}

Output:

System.String STATIC_Prop
System.String Prop
System.String BaseProp

This seems to only adress the static properties of the target type and the non static properties of the target type and the base type. But i want the static property of the base type (STATIC_BaseProp)

Does anyone know how to do this?





Aucun commentaire:

Enregistrer un commentaire