Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 26, 2018 How to use annotation get key name? | ||||
---|---|---|---|---|
| ||||
Rust sample code: #[cfg(name = "users")] PHP sample code: /* @Table(name = "users") */ Java sample code: @Table(name = "users") How to use dlang get key name? |
March 26, 2018 Re: How to use annotation get key name? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brian | On Monday, 26 March 2018 at 08:29:31 UTC, Brian wrote:
> Rust sample code:
>
> #[cfg(name = "users")]
>
> PHP sample code:
>
> /*
> @Table(name = "users")
> */
>
> Java sample code:
>
> @Table(name = "users")
>
> How to use dlang get key name?
If I understand your question correctly:
struct Table {
string name;
}
struct Foo {
@Table("foo")
int n;
}
unittest {
import std.traits;
string name = getUDAs!(Foo.n, Table)[0].name;
}
--
Simen
|
March 27, 2018 Re: How to use annotation get key name? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjærås | On Monday, 26 March 2018 at 08:50:31 UTC, Simen Kjærås wrote:
> On Monday, 26 March 2018 at 08:29:31 UTC, Brian wrote:
>> Rust sample code:
>>
>> #[cfg(name = "users")]
>>
>> PHP sample code:
>>
>> /*
>> @Table(name = "users")
>> */
>>
>> Java sample code:
>>
>> @Table(name = "users")
>>
>> How to use dlang get key name?
>
> If I understand your question correctly:
>
> struct Table {
> string name;
> }
>
> struct Foo {
> @Table("foo")
> int n;
> }
>
> unittest {
> import std.traits;
>
> string name = getUDAs!(Foo.n, Table)[0].name;
> }
>
> --
> Simen
Thanks.
but you don't understand my means, I want have keys with multiple indeterminate names.
Rust sample code:
#[cfg(name1 = "users", name2 = "users111")]
PHP sample code:
/*
@Table(name2 = "users", name2 = "users111")
*/
Java sample code:
@Table(name2 = "users111", name1 = "users")
How to use dlang get key name?
Don't have support get key function?
How to do?
|
March 27, 2018 Re: How to use annotation get key name? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brian | On Tuesday, 27 March 2018 at 15:38:48 UTC, Brian wrote:
> but you don't understand my means, I want have keys with multiple indeterminate names.
You can pass an associative array (or better yet, a struct containing one) as a UDA and then use the regular loop over its keys and values.
struct Table { string[string] keys_and_values; }
@Table(["name1": "users", "name2" : "users111"])
void foo() {}
D's UDAs are just a value attached to the name, so all normal rules of types apply.
|
Copyright © 1999-2021 by the D Language Foundation