Enterprise Architect: C# Optional parameters?
Asked Answered
H

2

6

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?

Herbertherbicide answered 17/5, 2011 at 18:29 Comment(1)
Where are you seeing this error? Is it in the error window, produced from compiler, some other tool, etc ...Neysa
H
5

Sparx has just released version 9 of EA, which has support for C# 4.0.

Herat answered 17/5, 2011 at 18:46 Comment(1)
Wow, literally it came out today!Herbertherbicide
L
2

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.

Lexicography answered 17/5, 2011 at 18:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.