void AddInitializerToInstanceConstructors(TypeDefinition type, Method initializer)
{
int n = 0;
//count number of non-static constructors
foreach (TypeMember node in type.Members)
{
if (NodeType.Constructor == node.NodeType && !node.IsStatic)
n++;
}
//if there is more than one we need $initialized$ guard check
if (n > 1)
AddInitializedGuardToInitializer(type, initializer);
foreach (TypeMember node in type.Members)
{
if (NodeType.Constructor == node.NodeType && !node.IsStatic)
{
Constructor constructor = (Constructor) node;
n = GetIndexAfterSuperInvocation(constructor.Body);
foreach (Statement st in initializer.Body.Statements)
{
constructor.Body.Insert(n, (Statement) st.Clone());
n++;
}
foreach (Local loc in initializer.Locals)
{
constructor.Locals.Add(loc);
}
}
}
}