bool BaseGenericObject::addProperty(const char* name, const Variant& value, MetaData metadata, bool enableNotification) { const IClassDefinition& definition = *this->getDefinition(); ObjectHandle provider = this->getDerivedType(); auto definitionModifier = definition.getDetails().getDefinitionModifier(); if (definitionModifier == nullptr) { return false; } Collection testCollection; bool isCollection = value.tryCast<Collection>(testCollection); if (!definitionModifier->addProperty(name, value.type()->typeId(), std::move(metadata), isCollection)) { return false; } PropertyAccessor accessor = definition.bindProperty(name, provider); if (enableNotification) { return accessor.setValue(value); } else { return accessor.setValueWithoutNotification(value); } }
bool BaseGenericObject::setProperty(const char* name, const Variant& value, bool enableNotification) { // Get existing property const IClassDefinition& definition = *this->getDefinition(); ObjectHandle provider = this->getDerivedType(); PropertyAccessor accessor = definition.bindProperty(name, provider); // do nothing if property does not exist and the value is void if (!accessor.isValid() && value.isVoid()) { return false; } // set value to the property if property exists and the value is not void if (accessor.isValid() && !value.isVoid()) { if (enableNotification) { return accessor.setValue(value); } else { return accessor.setValueWithoutNotification(value); } } // Property does not exist // Add new property and set it auto definitionModifier = definition.getDetails().getDefinitionModifier(); if (definitionModifier == nullptr) { return false; } if (accessor.isValid() && value.isVoid()) { definitionModifier->removeProperty(name); return false; } return addProperty(name, value, nullptr, enableNotification); }