mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Fixed FieldInfo.SetValue for objects
This commit is contained in:
parent
767ced3563
commit
21e2269d43
2 changed files with 13 additions and 2 deletions
|
@ -76,7 +76,10 @@ namespace System.Reflection
|
|||
|
||||
if (valueType == fieldType)
|
||||
{
|
||||
Internal.MemCpy(fieldDataAddr, valueDataAddr, fieldType.[Friend]mSize);
|
||||
if (valueType.IsObject)
|
||||
*((void**)fieldDataAddr) = Internal.UnsafeCastToPtr(value);
|
||||
else
|
||||
Internal.MemCpy(fieldDataAddr, valueDataAddr, fieldType.[Friend]mSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -84,6 +84,7 @@ namespace Tests
|
|||
[AttrB(44, 55)]
|
||||
public int mB = 2;
|
||||
public int mC = 3;
|
||||
public String mStr = "ABC";
|
||||
}
|
||||
|
||||
[Reflect(.Type)]
|
||||
|
@ -171,7 +172,7 @@ namespace Tests
|
|||
fieldIdx++;
|
||||
}
|
||||
|
||||
let fieldInfo = cb.GetType().GetField("mC").Value;
|
||||
var fieldInfo = cb.GetType().GetField("mC").Value;
|
||||
int cVal = 0;
|
||||
fieldInfo.GetValue(cb, out cVal);
|
||||
fieldInfo.SetValue(cb, cVal + 1000);
|
||||
|
@ -180,6 +181,13 @@ namespace Tests
|
|||
Variant variantVal = Variant.Create(123);
|
||||
fieldInfo.SetValue(cb, variantVal);
|
||||
Test.Assert(cb.mC == 123);
|
||||
|
||||
fieldInfo = cb.GetType().GetField("mStr").Value;
|
||||
String str = null;
|
||||
fieldInfo.GetValue(cb, out str);
|
||||
Test.Assert(str == "ABC");
|
||||
fieldInfo.SetValue(cb, "DEF");
|
||||
Test.Assert(cb.mStr == "DEF");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue