PropDescriptor

Describes a property declared in an aggregate.

A property is described by a name, a setter and a getter. Several constructors allow to define the descriptor using a setter, a getter but also a pointer to the targeted field. Another useful member is the pointer to the Rtti structure matching to the descriptor specialization.

Constructors

this
this(PropSetter aSetter, PropGetter aGetter, string aName = "")

Constructs a property descriptor from a PropSetter and a PropGetter.

this
this(PropSetterConst aSetter, PropGetter aGetter, string aName = "")

Constructs a property descriptor from a PropSetterConst and a PropGetter.

this
this(PropSetter aSetter, T* aSourceData, string aName = "")

Constructs a property descriptor from a PropSetter and as getter a pointer to a variable.

this
this(T* aData, string aName = "")

Constructs a property descriptor from a pointer to a variable used as a setter and getter.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Postblit

Copying this object is disabled.

A postblit is present on this object, but not explicitly documented in the source.

Members

Aliases

PropGetter
alias PropGetter = T delegate()

getter prototype

PropGetter
alias PropGetter = T delegate()

getter prototype

PropSetter
alias PropSetter = void delegate(T value)

setter proptotype

PropSetter
alias PropSetter = void delegate(T value)

setter proptotype

PropSetterConst
alias PropSetterConst = void delegate(const T value)

alternative setter prototype.

PropSetterConst
alias PropSetterConst = void delegate(const T value)

alternative setter prototype.

Functions

as
PropDescriptor!A* as()

Returns this descriptor casted as pointer to a descriptor of the type given by template parameter.

declarator
void declarator(Object value)
Object declarator()

The object that declares this property. When really needed, this value is set automatically.

define
void define(PropSetter aSetter, PropGetter aGetter, string aName = "")

Defines a property descriptor from a PropSetter and a PropGetter.

define
void define(PropSetter aSetter, T* aSourceData, string aName = "")

Defines a property descriptor from a PropSetter and as getter a pointer to a variable.

define
void define(T* aData, string aName = "", Object aDeclarator = null)

Defines a property descriptor from a pointer to a variable used as a setter and getter.

genericDescriptor
PropDescriptor!int* genericDescriptor()

Returns this descriptor casted as pointer to a GenericDescriptor.

get
T get()

Gets the property value

getter
void getter(PropGetter value)
PropGetter getter()

Sets the property getter using a standard method.

hints
PropHints hints()

Returns the hints for this property.

name
void name(const(char)[] value)
const(Array!char) name()

Sets of gets the string used to identify the property

rtti
const(Rtti*) rtti()

Returns the RuntimeTypeInfo struct for the property type.

set
void set(T value)

Sets the property value

setDirectSource
void setDirectSource(T* value)

Sets the property getter using a pointer to a variable

setDirectTarget
void setDirectTarget(T* location)

Sets the property setter using a pointer to a variable

setter
void setter(PropSetter value)
PropSetter setter()

Sets the property setter using a standard method.

Examples

1 static struct Foo
2 {
3     private int _value = 1;
4     PropDescriptor!int valueDescriptor;
5 
6     void value(int v){_value = v;}
7     int value(){return _value;}
8 }
9 
10 Foo foo;
11 // defines the property using the setter and the getter.
12 foo.valueDescriptor.define(&foo.value, &foo.value, "foo.value");
13 // defines the property using the setter and a pointer to the field.
14 foo.valueDescriptor.define(&foo.value, &foo._value, "foo.value");
15 // .get and .set allow to access the property value
16 foo.valueDescriptor.set(2);
17 assert(foo.valueDescriptor.get == 2);
18 // getter() and setter() too but they are used to set/get the delegates.
19 foo.valueDescriptor.setter()(1);
20 assert(foo.valueDescriptor.getter()() == 1);
21 // a descriptor has a fixed size, whatever is it's specialization,
22 // that allows to cast safely to any other descriptor type.
23 PropDescriptor!float* fpDescr = cast(PropDescriptor!float*) &foo.valueDescriptor;
24 // that's why the halper "as" is provided to cast
25 PropDescriptor!byte* byteDescr = fpDescr.as!byte;
26 // and the actual type can be retrieved with the rtti
27 assert(fpDescr.rtti is getRtti!int);
28 assert(byteDescr.rtti is getRtti!int);

Meta