On 09/10/2019 03:32 AM, Andre Pany wrote:

>      @Foo void method0(){}
>
>      @Foo("abc") void method1(){}

The UDA syntax allows both types and an objects. method0 uses Foo type and method1 uses a Foo object. So, if your API allows both, your code that deals with UDA must account for both.

The simplest solution here is to have method0 take an object as well:

  @Foo() void method0(){}

If you want to allow for both, the UDA code must change similar to the following:

    static foreach(fieldName; __traits(allMembers, T))
    {
        static if (hasUDA!(__traits(getMember, T, fieldName), Foo))
        {
static if (is (getUDAs!(__traits(getMember, T, fieldName), Foo)[0])) {
            // The UDA is the type Foo
            pragma(msg, "Default Foo string: ", Foo.init.name);

          } else {
            // The UDA is a Foo object
pragma(msg, "Special Foo string: ", getUDAs!(__traits(getMember, T, fieldName), Foo)[0].name);
          }
        }
    }

Ali

Reply via email to