Can CodeDom create additional arguments when creating a C # method?

Can CodeDom create optional arguments when creating a C # method and provide a default value?

For instance:

public void ExampleMethod(int required
                          , string optionalstr = "default string"
                          , int optionalint = 10)

Solution I found a simple workaround for the problem, you can simply put the default value as part of the argument name:

CodeParameterDeclarationExpression(typeof(int), "optionalint = 5");

This works for me b / c. I am using CodeDom to create C # code. It will not work if you need to support multiple languages.

+5
source share
1 answer

Yes.

[Optional].
, [[DefaultParameterValue(...)]. ( 0 null, .

.

+4

All Articles