Enterprise Architect: C# Optional parameters?
-
14-11-2019 - |
Question
Any option to get Enterprise Architect to recognize optional parameters in C#?
I have attempted to import existing code and get the following error:
There was an error parsing C:\MyProject\FooBar.cs on line 30. Unexpected symbol: =
Code:
public void Foo(int bar = 1) //Line 30
{
}
I have also attempted to start from scratch and generate code from Enterprise Architect. I created a class, then added an operation to that class and defined the parameters. The form for editing parameters allows me to supply the "Name", "Type", and "Default" (as well as other information). I added Name: bar, Type: int, Default: 1. Then when I generated the code this is what I get (no optional parameter generated!)
namespace System {
public class FooBar {
///
/// <param name="bar"></param>
public void Foo(int bar){
}
}//end FooBar
}//end namespace System
What am I doing incorrectly?
Solution
Sparx has just released version 9 of EA, which has support for C# 4.0.
OTHER TIPS
Optional parameters are supported from C# 4.0 and up. If you are using an older version then using them will simply not work and result in the error you are mentioning.