Standard Library · meta
class AttrArg
One argument of an attribute, with a slot for every primitive form.
since 0.1.0-alpha.1linuxwindowswasm
Overview
Attribute fields are int, float, bool or string, so an argument carries four
values and only the one matching the attribute's field type is meaningful. The typed
accessors on Attr (argStr, argInt, argBool, argFloat) pick the right slot for you.
Examples
attribute Column { string col = ""; int width = 0; }
attribute Inspect { }
rule inspect {
match @Inspect(i) on class C
inject `Array<string> slots() => [ $for s in C.fields.where((f) => f.hasAttr("Column")).map((f) =>
f.attributes.at(0).args.at(0).s + "," + f.attributes.at(0).args.at(1).i.toString() + "," +
f.attributes.at(0).args.at(1).present.toString()) : $s ];` at member of C
}
@Inspect
class User {
@Column("full_name", 40) string name;
@Column("id") int id;
}
console.writeln(User().slots().joinToString("; "));
full_name,40,true; id,0,false
Fields
b
bool bThe value when the attribute field is a bool.
f
float fThe value when the attribute field is a float.
i
int iThe value when the attribute field is an int.
present
bool presenttrue when the argument was written at the use site, false when it took its default.
s
string sThe value when the attribute field is a string.
See also
- Attr — An attribute written on a field or method, with the values of its arguments.