If I want a bunch of classes to implement a method, I can just make them implement an interface. However, if I want the method to always be decorated with two custom attributes, if there a syntax for that? In other words, I want every class that implement method Run() to attach a descriptionAttribute and a versionAttribute.
Update: Is there a way to make classes that implement Run() generate a compile error if they did not attach the two attributes?
public interface IRun
{
void Run();
}
public abstract class RunBase : IRun
{
[Description("Run Run Run")]
[Version("1.0")]
public abstract void Run();
}
public abstract class SoRunning : RunBase
{
public override void Run() {}
}
you should be able to get the Attributes off of the base class
There is no compile time way to enforce that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With