IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

C# Code-Gen Namespace-Filepath Options · View
Dion@sorna.com
Posted: Thursday, September 17, 2009 9:39:50 PM
Rank: Newbie

Joined: 9/17/2009
Posts: 4
Location: Eagan, MN
Ideally I would like to be able to generate code from models such that files are organized in directories according to namespaces. However, I only wish to generate directories relative to the project namespace.

For instance, if I had a fully qualified class: "Company.Common.Project1.MyNamespace.MyClass"

The Visual Studio solution encompasses everything within "Common" the project's root namespace would be "Company.Common.Project1".

Code generation for the Project1 component (project) would emit directories relative to "Project1". If the project were located at:
"D:\Team Server\Common\Project1" then the class source file would be emitted at: "D:\Team Server\Common\Project1\MyNameSpace\MyClass.cs"

I can "sort of" accomplish this by turning off the "use namespace for code file path" feature then and then defining separate components with assigned directories. However, the source files are not associated with the project in question. Moreover, when I manually associate the file with the existing project the realization association between class and sub-component are replaced with one between the class and the parent.

The only means of accomplishing what I want is to first create the Visual Studio class source file and let reverse-engineering model the relationship for me. Workable but not convenient.

Please advise.

Thanks,
--Dion
cor
Posted: Monday, September 21, 2009 10:34:26 AM
Rank: Advanced Member

Joined: 9/28/2005
Posts: 371
Location: Vienna
Hi Dion!

Unsure if I understood everything correctly.
Why did you turn off "use namespace for code file path"? Isn't this exactly what you want?

Did you try to reverse engineer your VS.NET project file (relative to the UMP file) => you should get a component referencing the VS.NET project file.
When you now add e.g. a class in Common::Project1::MyNameSpace in UModel, it should be written to the same directory as MyClass.cs (=> "D:\Team Server\Common\Project1\MyNameSpace").

If you still have problems, maybe you can send a small sample to our support center.
Dion@sorna.com
Posted: Wednesday, September 23, 2009 5:25:06 PM
Rank: Newbie

Joined: 9/17/2009
Posts: 4
Location: Eagan, MN
The "use namespace for code file path" is precisely what I'd like except that the legacy coding standards to which I am constrained on certain projects dictate rules that don't follow the Java methodology. By that I mean that each project within a solution should not contain the full directory tree in a perfect mirror of the namespace hierarchy. Rather, if a project (say "ProjectA") in a VS solution was assigned a root namespace of Company.ProjectA and was located on the filesystem at "D:\Team Server\SolutionC\ProjectA" then the fully qualified class named "Company.ProjectA.FeatureB.MyClass" should be placed within the file system as "D:\Team Server\SolutionC\ProjectA\FeatureB\MyClass.cs". However, with the "use namespace for code file path" option turned on the class will be emitted at "D:\Team Server\SolutionC\ProjectA\Company\ProjectA\FeatureB\MyClass.cs".

If I were to reverse engineer an existing project UModel would figure things out and map files to model correctly. However, should I model a new class in UModel it will create a new, full directory tree within the project directory beginning with the root namespace rather than the existing directory structure. This means that I have: "D:\Team Server\SolutionC\ProjectA\FeatureB\ExistingClass.cs" and "D:\Team Server\SolutionC\ProjectA\Company\ProjectA\FeatureB\NewClass.cs".

I hope this is a bit clearer.

Thanks,
--Dion
cor
Posted: Friday, September 25, 2009 11:08:18 AM
Rank: Advanced Member

Joined: 9/28/2005
Posts: 371
Location: Vienna
Hi Dion!

Clear now.
Currently, there is no built in possibilty for something like "partly use namespace for code file path".

I see two possibilities:

A) You can use one project file per namespace and use the option to "Generate missing ComponentRealization" => new classes will automatically get a ComponentRealization to the corresponding projectfile and come into the same (wanted) directory.
But I assume this is not feasible/convenient in your case!?

B) You write a small IDE plugin and set the code file path by yourself.
Again two possibilities:

B1) You listen to the OnAfterAddChild event and everytime a new class, interface,... is added, you immediately set its code file path to the directory of your choice (a bit similar to the DefaultPrefix sample, which automatically sets the prefix of new attributes, enumerationliterals,...).

B2) You introduce a new command, which goes over all classes, interfaces,... and sets the code file path to the wanted directory (directly before forward engineering).
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.