Handle casting both up and down inheritance tree
This commit is contained in:
parent
7769722c08
commit
8c3db0373b
|
@ -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});
|
||||
|
|
Loading…
Reference in New Issue