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();
|
var expectedType = scriptType.ResolveType();
|
||||||
if (expectedType.IsAssignableFrom(Type))
|
if (expectedType.IsAssignableFrom(Type))
|
||||||
return true;
|
return true;
|
||||||
|
if (Type.IsAssignableFrom(expectedType))
|
||||||
|
return true;
|
||||||
if (_implicitCasts.ContainsKey(expectedType))
|
if (_implicitCasts.ContainsKey(expectedType))
|
||||||
return true;
|
return true;
|
||||||
if (isExplicit && _explicitCasts.ContainsKey(expectedType))
|
if (isExplicit && _explicitCasts.ContainsKey(expectedType))
|
||||||
|
@ -149,6 +151,8 @@ namespace PorygonSharp.UserData
|
||||||
var objType = obj.GetType();
|
var objType = obj.GetType();
|
||||||
if (expectedType.IsAssignableFrom(objType))
|
if (expectedType.IsAssignableFrom(objType))
|
||||||
return objPtr;
|
return objPtr;
|
||||||
|
if (objType.IsAssignableFrom(expectedType))
|
||||||
|
return objPtr;
|
||||||
if (_implicitCasts.TryGetValue(expectedType, out var func))
|
if (_implicitCasts.TryGetValue(expectedType, out var func))
|
||||||
{
|
{
|
||||||
var castVal = func.Invoke(null, new[] {obj});
|
var castVal = func.Invoke(null, new[] {obj});
|
||||||
|
|
Loading…
Reference in New Issue