From 8c3db0373b87f8fdd59342fb96639df9597ee34f Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 7 Sep 2019 15:54:30 +0200 Subject: [PATCH] Handle casting both up and down inheritance tree --- PorygonSharp/UserData/UserData.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PorygonSharp/UserData/UserData.cs b/PorygonSharp/UserData/UserData.cs index e0e070f..10f6b0c 100644 --- a/PorygonSharp/UserData/UserData.cs +++ b/PorygonSharp/UserData/UserData.cs @@ -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});