Search code examples
c#visual-studioclass-diagram

How do I select namespace into which generated C# classes are put?


I'm generating a platoon of C# classes from an UML Class Diagram in Visual Studio 2013 (Update 5). When generated, a new "SchematicsLib" project appears in my solution, and the generated code is then placed into the "GeneratedCode" folder of this new project, no namespaces.

MyProject
|-- App_Code
|   |-- Entities
|   `-- ...
`-- ...

SchematicsLib
`-- GeneratedCode
    |-- GeneratedClassA.cs
    `-- ...

MyProjectDiagrams
`-- classes.classdiagram

I'd wish to place the generated code into a folder (reflecting namespace structure) in an existing project of mine, to MyProject/App_Code/Entities - the classes should also be wrapped in the namespace MyProject.App_Code.Entities as well. How may I accomplish this if I'd wish to keep code generation to a single step?


Solution

  • You will need to define a namespace on your UML. Here are directions on how to do this. Another page in that article states:

    If the UML type is contained in a package, the generated C# type is placed inside a namespace, and the file is generated in a folder that has the same name as the namespace.