mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +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)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -84,6 +84,7 @@ namespace Tests
|
||||||
[AttrB(44, 55)]
|
[AttrB(44, 55)]
|
||||||
public int mB = 2;
|
public int mB = 2;
|
||||||
public int mC = 3;
|
public int mC = 3;
|
||||||
|
public String mStr = "ABC";
|
||||||
}
|
}
|
||||||
|
|
||||||
[Reflect(.Type)]
|
[Reflect(.Type)]
|
||||||
|
@ -171,7 +172,7 @@ namespace Tests
|
||||||
fieldIdx++;
|
fieldIdx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
let fieldInfo = cb.GetType().GetField("mC").Value;
|
var fieldInfo = cb.GetType().GetField("mC").Value;
|
||||||
int cVal = 0;
|
int cVal = 0;
|
||||||
fieldInfo.GetValue(cb, out cVal);
|
fieldInfo.GetValue(cb, out cVal);
|
||||||
fieldInfo.SetValue(cb, cVal + 1000);
|
fieldInfo.SetValue(cb, cVal + 1000);
|
||||||
|
@ -180,6 +181,13 @@ namespace Tests
|
||||||
Variant variantVal = Variant.Create(123);
|
Variant variantVal = Variant.Create(123);
|
||||||
fieldInfo.SetValue(cb, variantVal);
|
fieldInfo.SetValue(cb, variantVal);
|
||||||
Test.Assert(cb.mC == 123);
|
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