Add error message for missing parameter-less constructor (#233)

* Add error message for missing parameter-less constructor

* Add error message for missing parameter-less constructor
This commit is contained in:
Matt Jaeger 2019-01-02 19:56:00 -08:00 committed by Paul Pacheco
parent eb1863a96c
commit 4a3fc70d14

View File

@ -1,4 +1,5 @@
// SyncList code
using System;
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
@ -27,7 +28,17 @@ public static void GenerateSyncListInstanceInitializer(ILProcessor ctorWorker, F
// Not initialized by the user in the field definition, e.g:
// public SyncListInt Foo;
var listCtor = Weaver.scriptDef.MainModule.ImportReference(fd.FieldType.Resolve().Methods.First<MethodDefinition>(x => x.Name == ".ctor" && !x.HasParameters));
MethodReference listCtor;
try
{
listCtor = Weaver.scriptDef.MainModule.ImportReference(fd.FieldType.Resolve().Methods.First<MethodDefinition>(x => x.Name == ".ctor" && !x.HasParameters));
}
catch (Exception)
{
Weaver.fail = true;
Log.Error($"Missing parameter-less constructor for: {fd.FieldType.Name}");
return;
}
ctorWorker.Append(ctorWorker.Create(OpCodes.Ldarg_0));
ctorWorker.Append(ctorWorker.Create(OpCodes.Newobj, listCtor));