__traits() to get parameter details only ? ... hasMember looks up everything within
someone
someone at somewhere.com
Wed Aug 4 22:09:16 UTC 2021
On Wednesday, 4 August 2021 at 16:41:04 UTC, Alexandru Ermicioi
wrote:
> On Wednesday, 4 August 2021 at 15:08:24 UTC, someone wrote:
>
>> However, __traits(hasMember, ...) checks for the existence of
>> anything labeled lstrCurrencyID within the class (eg:
>> unrelated variables with same name; not gonna happen, but, I
>> like to code it the right way); so, question is: is there any
>> way to search the parameter declarations only ?
>>
>> Something akin to
>> https://dlang.org/spec/traits.html#getParameterStorageClasses
>> but for the parameter types/labels
>
> What do you mean by parameter type?
> Are you referring to @property functions or just whether there
> is a field in there?
Labels, identifiers I meant, I suppose I heavily redacted and
types stuck, sorry for the confusion.
> In both cases you need to get that symbol with
> __traits(getMember ...).
> If it is about @property then check whether the symbol is a
> function and if so fetch the function attributes with
> functionAttributes template and check if it is marked as a
> property.
Nope. Nothing about @property. Furthermore, as a side-note: I
removed all @property usage from my code and I am not using them
anymore since this language feature seems to be half-baked from
what I am seeing here in the forums.
> If this is about field of the class then you can test with
> FieldNameTuple.
>
> Since you're using classes consider just declaring an interface
> that denotes that implementor has this field, it would be much
> easier to check for it, and easier for compiler since it avoids
> compile time magic.
>
> Best regards,
> Alexandru.
More information about the Digitalmars-d-learn
mailing list