mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-18 16:10:26 +02:00
Reflection field value fixes and tests
This commit is contained in:
parent
d4c78c0799
commit
d864a912c5
3 changed files with 41 additions and 1 deletions
|
@ -150,7 +150,7 @@ namespace System.Reflection
|
||||||
return &value;*/
|
return &value;*/
|
||||||
|
|
||||||
if (type.IsBoxed)
|
if (type.IsBoxed)
|
||||||
return ((uint8*)(void*)value) + type.[Friend]mMemberDataOffset;
|
return ((uint8*)Internal.UnsafeCastToPtr(value)) + type.[Friend]mMemberDataOffset;
|
||||||
return ((uint8*)Internal.UnsafeCastToPtr(value));
|
return ((uint8*)Internal.UnsafeCastToPtr(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -733,6 +733,12 @@ namespace System.Reflection
|
||||||
public override bool IsSubtypeOf(Type checkBaseType)
|
public override bool IsSubtypeOf(Type checkBaseType)
|
||||||
{
|
{
|
||||||
TypeInstance curType = this;
|
TypeInstance curType = this;
|
||||||
|
if (curType.IsBoxed)
|
||||||
|
{
|
||||||
|
curType = curType.UnderlyingType as TypeInstance;
|
||||||
|
if (curType == null)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (curType == checkBaseType)
|
if (curType == checkBaseType)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma warning disable 168
|
#pragma warning disable 168
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Tests
|
namespace Tests
|
||||||
{
|
{
|
||||||
|
@ -124,6 +125,13 @@ namespace Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Reflect, AlwaysInclude(AssumeInstantiated=true, IncludeAllMethods=true)]
|
||||||
|
struct StructB
|
||||||
|
{
|
||||||
|
public int mA;
|
||||||
|
public String mB;
|
||||||
|
}
|
||||||
|
|
||||||
class ClassA2 : ClassA
|
class ClassA2 : ClassA
|
||||||
{
|
{
|
||||||
public override int GetA(int32 a)
|
public override int GetA(int32 a)
|
||||||
|
@ -470,5 +478,31 @@ namespace Tests
|
||||||
methodIdx++;
|
methodIdx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
static void TestStructB()
|
||||||
|
{
|
||||||
|
StructB sb;
|
||||||
|
sb.mA = 25;
|
||||||
|
sb.mB = "Struct B";
|
||||||
|
|
||||||
|
let type = sb.GetType() as TypeInstance;
|
||||||
|
let fields = type.GetFields();
|
||||||
|
int fieldIdx = 0;
|
||||||
|
for (let field in fields)
|
||||||
|
{
|
||||||
|
let refP = field.GetValue(sb);
|
||||||
|
switch (fieldIdx)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Test.Assert(refP.Value.Get<int>() == 25);
|
||||||
|
case 1:
|
||||||
|
Test.Assert(refP.Value.Get<String>() === "Struct B");
|
||||||
|
case 2:
|
||||||
|
Test.FatalError();
|
||||||
|
}
|
||||||
|
fieldIdx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue