MethodDeclaration Class
Represents a method declaration.
public class MethodDeclaration : MemberDeclaration, IParametrableTypeExample
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
MemberDeclarationMethodDeclaration- Implements
Constructors
| Name | Description |
|---|---|
| MethodDeclaration() | |
| MethodDeclaration(string?) | Initializes a new instance of the MethodDeclaration class with the specified name. |
MethodDeclaration overloads
MethodDeclaration()
MethodDeclaration.cspublic MethodDeclaration()No documentation is available.
MethodDeclaration(string?)
MethodDeclaration.csInitializes a new instance of the MethodDeclaration class with the specified name.
public MethodDeclaration(string? name)Parameters
namestring?- The method name.
Properties
| Name | Description |
|---|---|
| Arguments | |
| Modifiers | |
| Parameters | |
| PrivateImplementationType | |
| ReturnType | |
| Statements |
Arguments
MethodDeclaration.csModifiers
MethodDeclaration.csParameters
MethodDeclaration.cspublic CodeObjectCollection<TypeParameter> Parameters { get; }Property value
No documentation is available.
PrivateImplementationType
MethodDeclaration.cspublic TypeReference? PrivateImplementationType { get; set; }Property value
No documentation is available.