nikobarli
Topic Author
Posts: 178
Joined: 26 Apr 2017, 06:23

(C++) Defining a property with the backing field's methods as getter/setter

29 Aug 2017, 06:58

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.
    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);
        }
    }

 
User avatar
jsantos
Site Admin
Posts: 2900
Joined: 20 Jan 2012, 17:18
Contact:

Re: (C++) Defining a property with the backing field's methods as getter/setter

30 Aug 2017, 17:08

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.
 
nikobarli
Topic Author
Posts: 178
Joined: 26 Apr 2017, 06:23

Re: (C++) Defining a property with the backing field's methods as getter/setter

31 Aug 2017, 04:16

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: ivan.fuertes and 0 guests