dimanche 15 janvier 2023

I can't get access to static properties or fields of my generic base class in C#

This is the code of my base class:

namespace Business;

public abstract class Business<ReadModel, WriteModel> : ReadBusiness<ReadModel>
    where ReadModel : class, IEntity, new()
    where WriteModel : class, IEntity, new()
{
    protected abstract Write<WriteModel> Write { get; }

    public static List<Action<WriteModel>> PreCreationAugmenters = new List<Action<WriteModel>>();

    public static List<Action<WriteModel>> PostCreationAugmenters = new List<Action<WriteModel>>();

    public static List<Action<WriteModel>> PreUpdateAugmenters = new List<Action<WriteModel>>();

And this is my derived class:

namespace Taxonomy;

public class TagBusiness : Business<TagView, Tag>
{

And now I want to access the PostCreationAugmenters of the base class from typeof(TagBusiness).

I tried:

typeof(TagBusiness).GetProperty("PostCreationAugmenters", BindingFlags.Static); // null
typeof(TagBusiness).GetField("PostCreationAugmenters", BindingFlags.Static); //null
typeof(TagBusiness).BaseType.GetProperty("PostCreationAugmenters"); // null

I want to get access to that list, and add an augmenter to it.

What do I do wrong here?





Aucun commentaire:

Enregistrer un commentaire