-
Notifications
You must be signed in to change notification settings - Fork 21
Description
There is the namespace parameter in GenerateAutomaticInterfaceAttribute which allows you to specify custom namespace.
However most of time you only want to add a suffix to the current namespace, like SomeNamespace.Interfaces or SomeNamespace.Abstractions.
It can be very simple in case the namespace consist of 1 part so you can use $"{nameof(SomeNamespace).Interfaces}". But usually you have 2+ parts. In this situation you have 2 ways:
- use raw strings, which is bad because once you want to rename something it will not automatically rename the part of raw string
- use multiple
nameofs, which is bad because:- it increase complexity, like:
Example.A.B->${nameof(Example)}.{nameof(Example.A)}}.{nameof(Example.A.B)}.Inerfaces") - you will need to update it in case you added/removed some part of namespace
- it increase complexity, like:
My proposition is allow namespace parameter to accept * and replace it will the current namespace:
using MyNamespace.Interfaces;
namespace MyNamespace;
[GenerateAutomaticInterfaceAttribute(namespace="*.Interfaces")]
class MyClass : IMyClass
{
}We can even go further and allow to use index/range syntax ([x], [x..y], [x..] and [..x] expressions) to refer to some parts of namespace by their indexes:
using Brand.Name.Interfaces.Repositories;
namespace Brand.Name.Repositories;
[GenerateAutomaticInterfaceAttribute(namespace="[..1].Interfaces.[1..]")]
class MyClass : IMyClass
{
}The index/range syntax is probably an overengineering and will be used by 0.0001% of the library users. But the wildcard syntax seems very solid and useful.
What do you think?