Auto-Implemented properties
michaelc37
michaelc37 at msn.com
Sat Jan 5 14:40:32 PST 2013
i was trying to make a D template to mimic auto-implemented
properties in c#.
I think i got it to work but when i tried to give the template a
more meaning full name like AutoImplementedProperty i get a
compile error "a.title is not an lvalue".
Is this a bug?
Is there a more suitable way of doing this?
c# e.g:
class Bar
{
public string Title { get; set; }
}
my attempt:
class Bar
{
alias autoproperty!(string, "get", "set") title
}
template autoproperty(T, args...)
{
import std.typetuple;
@property
{
private T _name;
static if (args.length)
{
static if (staticIndexOf!("get", args) > -1)
{
public T autoproperty()
{
return _name;
}
}
static if (staticIndexOf!("set", args) > -1)
{
public void autoproperty(T value)
{
_name = value;
}
}
}
}
}
void main(string[] args)
{
Bar a = new Bar();
a.title = "asf";
writefln(a.title);
return;
}
More information about the Digitalmars-d-learn
mailing list