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:
if (typeof(IList).IsAssignableFrom(type))
return CreateListEvalValue((IList)o, type);
if (!UserDataHandler.IsTypeRegistered(type))
return null;
if (!UserDataHandler.IsTypeRegistered(type) && !UserDataHandler.TryResolveType(type))
{
throw new Exception($"Type is not registered for use: {type.FullName}");
}
var typeHash = UserDataHandler.GetTypeId(type);
var handle = GCHandle.Alloc(o, GCHandleType.WeakTrackResurrection);
return new EvalValue(CreateUserDataEvalValue(typeHash, GCHandle.ToIntPtr(handle)));