| 127 | } |
| 128 | |
| 129 | void Object::SetFieldByName(const String& field, const Value& value, const DebugInfo& debugInfo) |
| 130 | { |
| 131 | Type::Ptr type = GetReflectionType(); |
| 132 | |
| 133 | if (!type) |
| 134 | BOOST_THROW_EXCEPTION(ScriptError("Cannot set field on object.", debugInfo)); |
| 135 | |
| 136 | int fid = type->GetFieldId(field); |
| 137 | |
| 138 | if (fid == -1) |
| 139 | BOOST_THROW_EXCEPTION(ScriptError("Attribute '" + field + "' does not exist.", debugInfo)); |
| 140 | |
| 141 | try { |
| 142 | SetField(fid, value); |
| 143 | } catch (const boost::bad_lexical_cast&) { |
| 144 | Field fieldInfo = type->GetFieldInfo(fid); |
| 145 | Type::Ptr ftype = Type::GetByName(fieldInfo.TypeName); |
| 146 | BOOST_THROW_EXCEPTION(ScriptError("Attribute '" + field + "' cannot be set to value of type '" + value.GetTypeName() + "', expected '" + ftype->GetName() + "'", debugInfo)); |
| 147 | } catch (const std::bad_cast&) { |
| 148 | Field fieldInfo = type->GetFieldInfo(fid); |
| 149 | Type::Ptr ftype = Type::GetByName(fieldInfo.TypeName); |
| 150 | BOOST_THROW_EXCEPTION(ScriptError("Attribute '" + field + "' cannot be set to value of type '" + value.GetTypeName() + "', expected '" + ftype->GetName() + "'", debugInfo)); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | void Object::Validate([[maybe_unused]] int types, const ValidationUtils&) |
| 155 | { |
nothing calls this directly
no test coverage detected