Enterprise Architect: Code generation for "using" statement
I have a question regarding the C# code generation capabilities of Enterprise Architect. How is it possible to add "using" statements? Say if we want to have System.Thread as a namespace in our file. Where do we specify this in the model?
I already tried to backward e开发者_Python百科ngineer the code with an inserted "using System.Thread", but could not detect this information anywhere in the model.
You don't add the "using" statements explicitly, they are inserted implicitly by the code generation facility where needed (the same applies to "imports" in Java). EA works it out by determining whether the referred class is in the same package.
If you want the exact details on how it does so, the code generation scripts are actually available for reading and editing (not recommended!) from Settings - Code Generation Templates. Select the language in the upper left corner, then start reading from the "File" script, which is the one that calls all the others. This is not an errand for the faint-hearted, but it's there if you want it.
I'm not sure whether "using" statements are generated correctly for classes which you'd normally consider part of standard libraries, such as System.Thread. You may need to add a System package with a Thread class in it (in a separate namespace) to get that to work properly.
精彩评论