Skip to content

[Proposal] Add a possibility to specify namespace suffix without a need to specify the whole namespace name #83

@iikuzmychov

Description

@iikuzmychov

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:

  1. use raw strings, which is bad because once you want to rename something it will not automatically rename the part of raw string
  2. 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

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions