C#C
C#10mo ago
SWEETPONY

✅ How to make static field required to use from interface?

I have this interface:
public interface IEventProcessor
{
    public static IReadOnlyCollection<string> HandledEvents { get; } = [];
}


HandledEvents is static because I can easily read values from it using reflection and without Activator.CreateInstance

Processor example:
public sealed class FlightEventProcessor(JsonSerializerOptions serializerOptions): IEventProcessor
{
    public static string[] HandledEvents => ["FlightAdded", "FlightUpdated"];
}


the main problem HandledEvents can be easily removed from FlightEventProcessor and nothing will happens. compilator allows me to not implement this array inside every classes that inherit IEventProcessor
Was this page helpful?