protected virtual Constructor DefineDefaultConstructor (bool is_static)
{
// The default instance constructor is public
// If the class is abstract, the default constructor is protected
// The default static constructor is private
Modifiers mods;
ParametersCompiled parameters = null;
if (is_static) {
mods = Modifiers.STATIC | Modifiers.PRIVATE;
parameters = ParametersCompiled.EmptyReadOnlyParameters;
} else {
mods = ((ModFlags & Modifiers.ABSTRACT) != 0) ? Modifiers.PROTECTED : Modifiers.PUBLIC;
parameters = PrimaryConstructorParameters ?? ParametersCompiled.EmptyReadOnlyParameters;
}
var c = new Constructor (this, MemberName.Name, mods, null, parameters, Location);
if (Kind == MemberKind.Class)
c.Initializer = new GeneratedBaseInitializer (Location, PrimaryConstructorBaseArguments);
if (PrimaryConstructorParameters != null && !is_static) {
c.IsPrimaryConstructor = true;
c.caching_flags |= Flags.MethodOverloadsExist;
}
AddConstructor (c, true);
if (PrimaryConstructorBlock == null) {
c.Block = new ToplevelBlock (Compiler, parameters, Location) {
IsCompilerGenerated = true
};
} else {
c.Block = PrimaryConstructorBlock;
}
return c;
}