MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / SetFieldValue

Method SetFieldValue

Source/Engine/Scripting/BinaryModule.cpp:1509–1568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1507}
1508
1509bool ManagedBinaryModule::SetFieldValue(void* field, const Variant& instance, Variant& value)
1510{
1511#if USE_CSHARP
1512 bool isStatic;
1513 MClass* parentClass;
1514 StringAnsiView name;
1515 if ((uintptr)field & ManagedBinaryModuleFieldIsPropertyBit)
1516 {
1517 const auto mProperty = (MProperty*)((uintptr)field & ~ManagedBinaryModuleFieldIsPropertyBit);
1518 isStatic = mProperty->IsStatic();
1519 parentClass = mProperty->GetParentClass();
1520 name = mProperty->GetName();
1521 }
1522 else
1523 {
1524 const auto mField = (MField*)field;
1525 isStatic = mField->IsStatic();
1526 parentClass = mField->GetParentClass();
1527 name = mField->GetName();
1528 }
1529
1530 // Get instance object
1531 MObject* instanceObject = nullptr;
1532 if (!isStatic)
1533 {
1534 // Box instance into C# object
1535 instanceObject = MUtils::BoxVariant(instance);
1536
1537 // Validate instance
1538 if (!instanceObject || !MCore::Object::GetClass(instanceObject)->IsSubClassOf(parentClass))
1539 {
1540 if (!instanceObject)
1541 {
1542 LOG(Error, "Failed to set '{0}.{1}' without object instance", String(parentClass->GetFullName()), String(name));
1543 }
1544 else
1545 {
1546 LOG(Error, "Failed to set '{0}.{1}' with invalid object instance of type '{2}'", String(parentClass->GetFullName()), String(name), String(MUtils::GetClassFullname(instanceObject)));
1547 }
1548 return true;
1549 }
1550 }
1551
1552 // Set the value
1553 bool failed = false;
1554 if ((uintptr)field & ManagedBinaryModuleFieldIsPropertyBit)
1555 {
1556 const auto mProperty = (MProperty*)((uintptr)field & ~ManagedBinaryModuleFieldIsPropertyBit);
1557 mProperty->SetValue(instanceObject, MUtils::VariantToManagedArgPtr(value, mProperty->GetType(), failed), nullptr);
1558 }
1559 else
1560 {
1561 const auto mField = (MField*)field;
1562 mField->SetValue(instanceObject, MUtils::VariantToManagedArgPtr(value, mField->GetType(), failed));
1563 }
1564 return failed;
1565#else
1566 return true;

Callers 2

AccessVariantFunction · 0.45
InvokeMethod · 0.45

Calls 8

GetClassFullnameFunction · 0.85
IsStaticMethod · 0.80
GetClassFunction · 0.50
StringFunction · 0.50
GetNameMethod · 0.45
IsSubClassOfMethod · 0.45
SetValueMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected