Skip to content

ConstructorBuilder

Create constructor declarations.

See also: Emit Overview | TypeBuilder | MethodBuilder

Factory Methods

Method Description
For(string typeName) Create a constructor for the given type

Modifiers

ctor.WithAccessibility(Accessibility.Public)
ctor.WithAccessibility("public")  // from snapshot or ValidSymbol.AccessibilityString
ctor.AsStatic()
ctor.AsPrimary()  // for primary constructors

Parameters

ctor.AddParameter("name", "string")
ctor.AddParameter("email", "string", p => p.WithDefaultValue("null"))
ctor.AddParameter(parameterBuilder)

Body

ctor.WithBody(body => body
    .AddStatement("Name = name;")
    .AddStatement("Email = email;"))

Constructor Chaining

ctor.CallsBase("name", "email")  // : base(name, email)
ctor.CallsThis("name")           // : this(name)

Attributes & XML Documentation

ctor.WithAttribute("Obsolete")
ctor.WithXmlDoc("Initializes a new instance of the Customer class.")

Properties

ctor.IsPrimary      // bool
ctor.Parameters     // ImmutableArray<ParameterBuilder>
ctor.Usings         // ImmutableArray<string>