mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
using if instead of try catch (#1740)
This commit is contained in:
parent
c25b1c6043
commit
a523d5f521
@ -1,5 +1,3 @@
|
||||
// SyncObject code
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Mono.CecilX;
|
||||
using Mono.CecilX.Cil;
|
||||
@ -37,16 +35,16 @@ static void GenerateSyncObjectInstanceInitializer(ILProcessor ctorWorker, FieldD
|
||||
|
||||
// Not initialized by the user in the field definition, e.g:
|
||||
// public SyncListInt Foo;
|
||||
MethodReference objectConstructor;
|
||||
try
|
||||
{
|
||||
objectConstructor = Weaver.CurrentAssembly.MainModule.ImportReference(fd.FieldType.Resolve().Methods.First<MethodDefinition>(x => x.Name == ".ctor" && !x.HasParameters));
|
||||
}
|
||||
catch (Exception)
|
||||
|
||||
TypeDefinition fieldType = fd.FieldType.Resolve();
|
||||
// find ctor with no parameters
|
||||
MethodDefinition ctor = fieldType.Methods.FirstOrDefault(x => x.Name == ".ctor" && !x.HasParameters);
|
||||
if (ctor == null)
|
||||
{
|
||||
Weaver.Error($"{fd} does not have a default constructor");
|
||||
return;
|
||||
}
|
||||
MethodReference objectConstructor = Weaver.CurrentAssembly.MainModule.ImportReference(ctor);
|
||||
|
||||
ctorWorker.Append(ctorWorker.Create(OpCodes.Ldarg_0));
|
||||
ctorWorker.Append(ctorWorker.Create(OpCodes.Newobj, objectConstructor));
|
||||
|
Loading…
Reference in New Issue
Block a user