Handle casting both up and down inheritance tree

This commit is contained in:
Deukhoofd 2019-09-07 15:54:30 +02:00
parent 7769722c08
commit 8c3db0373b
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 4 additions and 0 deletions

View File

@ -134,6 +134,8 @@ namespace PorygonSharp.UserData
var expectedType = scriptType.ResolveType();
if (expectedType.IsAssignableFrom(Type))
return true;
if (Type.IsAssignableFrom(expectedType))
return true;
if (_implicitCasts.ContainsKey(expectedType))
return true;
if (isExplicit && _explicitCasts.ContainsKey(expectedType))
@ -149,6 +151,8 @@ namespace PorygonSharp.UserData
var objType = obj.GetType();
if (expectedType.IsAssignableFrom(objType))
return objPtr;
if (objType.IsAssignableFrom(expectedType))
return objPtr;
if (_implicitCasts.TryGetValue(expectedType, out var func))
{
var castVal = func.Invoke(null, new[] {obj});