xtd.properties - Reference Guide  3.0.0
another c#-like property accessor for C++11 and above.
properties - Reference Guide

properties

  • properties add c#-like property_ accessor to your c++ class.
  • properties is distributed as a single header file.

What is it ?

A property_ is a member that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and still helps promote the safety and flexibility of methods.

There are three types of properties :

readwrite_
The property_ accessor can be read and write.
class Foo {
public:
//...
property_<int> Number {
get_ {return this->number;},
set_ {this->number = value;}
};
//...
private:
int number = 0;
};
readonly_
The property_ accessor can be read only.
class Foo {
public:
//...
property_<int, readonly_> Number {
get_ {return this->number;}
};
//...
private:
int number = 0;
};
writeonly_
The property_ accessor can be write only.
class Foo {
public:
//...
property_<int, writeonly_> Number {
set_ {this->number = value;}
};
//...
private:
int number = 0;
};