Is it possible to omit namespaces in VS 2010 Ultim

2019-09-17 01:07发布

问题:

when designing UML models in Visual Studio 2010 Ultimate (with Visualization and Modeling Feature Pack 1) I always need to indicate the full Type name (including the namespace) in order to get code that compiles (when doing 'Generate Code...'). Is there a way to "import" namespaces into the model? I can 'Add Reference...' on the Modelling Project, but this won't work because VS puts it as a Layer Reference (which is something else unfortunately).

Being forced to indicate the whole namespace makes the UML diagrams really hard to read... Imagine this being one line in an UML class model:

+ GetTexture(device : Microsoft.Xna.Framework.Graphics.GraphicsDevice) : Microsoft.Xna.Framework.Graphics.Texture2D

Thanks for your help!

回答1:

I figured out it is possible, though not really the best idea.

Open Architecture -> Windows -> UML Model Explorer. Right click on "Modelling" and select "Properties". Expand Stereotypes -> C# namespace and enter all namespaces you wish to have reference in the generated code files ("using ...") under "Using namespace" as a semi-colon separated list.

The better way to do it is described in this post. The reason is that in this case the type is for sure the one you selected and clashes (with other types from other namespaces in the generated code file) cannot occur.