ConstructorDeclaration Class

Represents a constructor declaration.

public class ConstructorDeclaration : MemberDeclaration

Example

var cls = new ClassDeclaration("Person");
var ctor = cls.AddMember(new ConstructorDeclaration());
ctor.Modifiers = Modifiers.Public;
ctor.Arguments.Add(new MethodArgumentDeclaration(typeof(string), "name"));
ctor.Statements = new AssignStatement(new MemberReferenceExpression(new ThisExpression(), "_name"), new ArgumentReferenceExpression("name"));

Assert.Equal("""
    class Person
    {
        public Person(string name)
        {
            this._name = name;
        }
    }

    """, cls.ToCsharpString());
Inheritance
MemberDeclaration ConstructorDeclaration

Constructors

NameDescription
ConstructorDeclaration()

ConstructorDeclaration()

ConstructorDeclaration.cs
public ConstructorDeclaration()

No documentation is available.

Properties

NameDescription
Arguments
Initializer
Modifiers
ParentType
Statements
public MethodArgumentCollection Arguments { get; }

No documentation is available.

public ConstructorInitializer? Initializer { get; set; }

No documentation is available.

public Modifiers Modifiers { get; set; }

Property value

Modifiers

No documentation is available.

public TypeDeclaration? ParentType { get; }

Property value

TypeDeclaration?

No documentation is available.

public StatementCollection? Statements { get; set; }

Property value

StatementCollection?

No documentation is available.