void AddInitializedGuardToInitializer(TypeDefinition type, Method initializer)
{
Field field = GetFieldsInitializerInitializedField(type);
//run initializer code only if $initialized$ is false
//hmm quasi-notation would be lovely here
Block trueBlock = new Block();
trueBlock.Add(new GotoStatement(LexicalInfo.Empty, new ReferenceExpression("___initialized___")));
IfStatement cond = new IfStatement(CodeBuilder.CreateReference(field),
trueBlock, null);
initializer.Body.Insert(0, cond);
//set $initialized$ field to true
initializer.Body.Add(
CodeBuilder.CreateFieldAssignment(field, new BoolLiteralExpression(true)));
//label we're past the initializer
initializer.Body.Add(
new LabelStatement(LexicalInfo.Empty, "___initialized___"));
}