Throw exception when trying to resolve a userdata type that's not registered, instead of just returning null

This commit is contained in:
Deukhoofd 2019-09-07 12:17:23 +02:00
parent d13eb7d2d5
commit d830929290
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 4 additions and 2 deletions

View File

@ -43,8 +43,10 @@ namespace PorygonSharp.EvalValues
case TypeCode.Object: case TypeCode.Object:
if (typeof(IList).IsAssignableFrom(type)) if (typeof(IList).IsAssignableFrom(type))
return CreateListEvalValue((IList)o, type); return CreateListEvalValue((IList)o, type);
if (!UserDataHandler.IsTypeRegistered(type)) if (!UserDataHandler.IsTypeRegistered(type) && !UserDataHandler.TryResolveType(type))
return null; {
throw new Exception($"Type is not registered for use: {type.FullName}");
}
var typeHash = UserDataHandler.GetTypeId(type); var typeHash = UserDataHandler.GetTypeId(type);
var handle = GCHandle.Alloc(o, GCHandleType.WeakTrackResurrection); var handle = GCHandle.Alloc(o, GCHandleType.WeakTrackResurrection);
return new EvalValue(CreateUserDataEvalValue(typeHash, GCHandle.ToIntPtr(handle))); return new EvalValue(CreateUserDataEvalValue(typeHash, GCHandle.ToIntPtr(handle)));