private Method GetInitializerFor(TypeDefinition type, bool isStatic)
{
string methodName = isStatic ? "$static_initializer$" : "$initializer$";
Method method = (Method)type[methodName];
if (null == method)
{
if (isStatic)
{
if (!type.HasStaticConstructor)
{
// when the class doesnt have a static constructor
// yet, create one and use it as the static
// field initializer method
method = CodeBuilder.CreateStaticConstructor(type);
}
else
{
method = CreateInitializerMethod(type, methodName, TypeMemberModifiers.Static);
AddInitializerToStaticConstructor(type, (InternalMethod)method.Entity);
}
}
else
{
method = CreateInitializerMethod(type, methodName, TypeMemberModifiers.None);
}
type[methodName] = method;
}
return method;
}