private void EnsureStaticConstructor(TypeDefinition type)
{
var staticConstructor = type.Constructor(true);
if (staticConstructor == null)
{
FodyEnvironment.LogDebug($"\t\t\t{type.Name} - adding static constructor");
var voidType = _msCoreReferenceFinder.GetCoreTypeReference("Void");
staticConstructor = new MethodDefinition(".cctor", MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Static | MethodAttributes.RTSpecialName,
type.Module.Import(voidType));
var body = staticConstructor.Body;
body.SimplifyMacros();
body.Instructions.Add(Instruction.Create(OpCodes.Ret));
body.OptimizeMacros();
type.Methods.Add(staticConstructor);
FodyEnvironment.LogDebug($"\t\t\t{type.Name} - added static constructor");
}
}