Open astaerk opened 1 month ago
clarify if it would be better to mark the implementing classes for auto implementation
This feels more intuitive to me. Also less chance to cause weird side effects. Imagine a dev that's unfamiliar with this project tags some existing interface with AutoImplement to use it in just one class—now every other class running that interface gets it auto-implemented! That seems like it could break something. Marking auto-implement on the class itself avoids that.
yeah, that is exactly what I have in mind, too. On the other hand if manually implemented members will be detected and skipped nothing would break for existing implementations. And it is one thing less I have to do for all my implementing classes. Also this would mean you'd have to specify which interfaces should be automatically implemented on class level; because it's probably not all of them. This is why I somehow think about supporting both scenarios.
btw. I moved the attributes to namespace Basilisque.AutoImplementer.Annotations felt cleaner somehow
I just pushed a breaking change in comparison to the first test versions. The implementing class now has to have a marker attribute for auto implementation to work: Basilisque.AutoImplementer.Annotations.AutoImplementInterfaces The attribute on the implemented interface is now optional.
Examples with explicitly stated interfaces on the class:
public interface IMyInterface
{ }
[Basilisque.AutoImplementer.Annotations.AutoImplementInterfaces<IMyInterface>()]
public class MyImplementation1 : IMyInterface
{ }
[Basilisque.AutoImplementer.Annotations.AutoImplementInterfaces(typeof(IMyInterface))]
public class MyImplementation2 : IMyInterface
{ }
[Basilisque.AutoImplementer.Annotations.AutoImplementInterfaces<IMyInterface>()]
public class MyImplementation3
{ }
[Basilisque.AutoImplementer.Annotations.AutoImplementInterfaces(typeof(IMyInterface))]
public class MyImplementation4
{ }
Example with implicitly interface discovery (implemented interfaces that are marked with an attribute):
[Basilisque.AutoImplementer.Annotations.AutoImplementInterface]
public interface IMyInterface1
{ }
public interface IMyInterface2
{ }
[Basilisque.AutoImplementer.Annotations.AutoImplementInterfaces]
public class MyImplementation : IMyInterface1, IMyInterface2
{ /* only IMyInterface1 will be auto implemented because IMyInterface2 is not marked with an attribute */ }
Might be good to deprecate [Required] in favor of [AutoImplement(Required = true)]
info: Initial commits were on #1 and #3, should have been on this issue number