(C++) Defining a property with the backing field's methods as getter/setter
Assume that I have a class TestVM and I want to add a property "Test" to it. The property has its backing field of type TestProp.
Then I want to directly configure the getter/setter of the property to its backing fields methods. Is there anyway to do it ?
Currently I have to create a getter/setter inside TestVM and forward the call to the backing field method.
Then I want to directly configure the getter/setter of the property to its backing fields methods. Is there anyway to do it ?
Currently I have to create a getter/setter inside TestVM and forward the call to the backing field method.
Code: Select all
template<typename T>
class TestProp {
public:
// Set value
void Set(const T & val) { ... }
// Get value
const T & Get() const { ... }
};
class TestVM : public BaseComponent, public INotifyPropertyChanged {
private:
TestProp<NsString> backingField;
NS_IMPLEMENT_INLINE_REFLECTION(TestVM, BaseComponent)
{
NsMeta<TypeId>("TestVM");
NsImpl<INotifyPropertyChanged>();
// I can define TestVM::GetTest and TestVM::GetTest and call backingField.Get/Set, but is there more straightforward approach ?
// NsProp("Test", &TestVM::GetTest, &TestVM::SetTest);
}
}
Re: (C++) Defining a property with the backing field's methods as getter/setter
I am sorry to say that's not supported by the current architecture. Right now, getters and setters need to be declared as member functions of the type T. But we are working on a new architecture that will give more flexibility regarding this (and more things like supporting custom types for strings, custom collections instead of ObservableCollection, etc). We will give more information as soon as it is ready. Sorry for the inconvenience.
Re: (C++) Defining a property with the backing field's methods as getter/setter
Ok, thanks for the reply. I think I will just use macro when declaring the property as a workaround.
Who is online
Users browsing this forum: No registered users and 4 guests