digitalmars.D.learn - How to use annotation get key name?
- Brian (9/9) Mar 26 2018 Rust sample code:
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (15/24) Mar 26 2018 If I understand your question correctly:
- Brian (15/45) Mar 27 2018 Thanks.
- Adam D. Ruppe (9/11) Mar 27 2018 You can pass an associative array (or better yet, a struct
Rust sample code: PHP sample code: /* Table(name = "users") */ Java sample code: Table(name = "users") How to use dlang get key name?
Mar 26 2018
On Monday, 26 March 2018 at 08:29:31 UTC, Brian wrote:Rust sample code: 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
Mar 26 2018
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:Thanks. but you don't understand my means, I want have keys with multiple indeterminate names. Rust sample code: 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?Rust sample code: 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
Mar 27 2018
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.
Mar 27 2018