MethodDeclaration Class

Represents a method declaration.

public class MethodDeclaration : MemberDeclaration, IParametrableType

Example

var method = new MethodDeclaration("Calculate");
method.Modifiers = Modifiers.Public;
method.ReturnType = typeof(int);
method.Arguments.Add(new MethodArgumentDeclaration(typeof(int), "value"));
method.Statements = new ReturnStatement(new LiteralExpression(42));

Assert.Equal("""
    public int Calculate(int value)
    {
        return 42;
    }

    """, method.ToCsharpString());
Inheritance
MemberDeclaration MethodDeclaration
Implements

Constructors

NameDescription
MethodDeclaration()
MethodDeclaration(string?)Initializes a new instance of the MethodDeclaration class with the specified name.

MethodDeclaration overloads

MethodDeclaration()

MethodDeclaration.cs
public MethodDeclaration()

No documentation is available.

MethodDeclaration(string?)

MethodDeclaration.cs

Initializes a new instance of the MethodDeclaration class with the specified name.

public MethodDeclaration(string? name)
Parameters
name string?
The method name.

Properties

NameDescription
Arguments
Modifiers
Parameters
PrivateImplementationType
ReturnType
Statements
public MethodArgumentCollection Arguments { get; }

No documentation is available.

public Modifiers Modifiers { get; set; }

Property value

Modifiers

No documentation is available.

public CodeObjectCollection<TypeParameter> Parameters { get; }

No documentation is available.

PrivateImplementationType

MethodDeclaration.cs
public TypeReference? PrivateImplementationType { get; set; }

Property value

TypeReference?

No documentation is available.

public TypeReference? ReturnType { get; set; }

Property value

TypeReference?

No documentation is available.

public StatementCollection? Statements { get; set; }

Property value

StatementCollection?

No documentation is available.