UDA initialize a user defined type attribute field
Arjan
arjan at ask.me.to
Tue Feb 18 15:43:54 PST 2014
When a user defined type is used as an attribute like this:
// the attribute
struct MyAttrib
{
immutable string name;
imuttable int sz;
immutable string defaultvalue;
}
// using the attribute
class Data
{
// field 'id' has attribute MyAttrib with name and sz set to
'fancy name'
// and 10 resp.
@MyAttrib( "fancy name", 10 )
long id;
...
}
But how do I only set the MyAttrib.defaultvalue?
class OtherData
{
//@MyAttrib( ??defaultvalue = "null" ?? )
//@MyAttrib( string.init, int.init, "null" ) //seems to work?
long id;
...
}
MyAttrib instances may be initialized like this:
auto myattrib = { defaultvalue:"null" };
But this seems not possible when using MyAttrib as attribute.
More information about the Digitalmars-d-learn
mailing list