fix: fixing Initializer for generic synclists (#2328)

Weaver should initialize `public SyncList<int> myList;`  in the same way it does for `SyncListInt`
This commit is contained in:
James Frowen 2020-10-11 00:04:35 +01:00 committed by GitHub
parent ad48d511a1
commit 9bf8817245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,6 +46,13 @@ static void GenerateSyncObjectInstanceInitializer(ILProcessor worker, FieldDefin
} }
MethodReference objectConstructor = Weaver.CurrentAssembly.MainModule.ImportReference(ctor); MethodReference objectConstructor = Weaver.CurrentAssembly.MainModule.ImportReference(ctor);
// if is SyncList<int> instead of SyncListInt then we need to make the ctor generic
if (fd.FieldType.IsGenericInstance)
{
GenericInstanceType genericInstance = (GenericInstanceType)fd.FieldType;
objectConstructor = objectConstructor.MakeHostInstanceGeneric(genericInstance);
}
worker.Append(worker.Create(OpCodes.Ldarg_0)); worker.Append(worker.Create(OpCodes.Ldarg_0));
worker.Append(worker.Create(OpCodes.Newobj, objectConstructor)); worker.Append(worker.Create(OpCodes.Newobj, objectConstructor));
worker.Append(worker.Create(OpCodes.Stfld, fd)); worker.Append(worker.Create(OpCodes.Stfld, fd));