views:

38

answers:

5

Hi,

I have a small issue with one of my projects, I have an entity called Image which is used to stored information about uploaded images in a CMS system I have created.

This hides the system.drawing.image this was not an issue until I needed to start doing image manipulation on a page which uses both classes.

At the moment in the declarations I have Using Image = myCMS.Entities.Image; So when calling Image I am using my object, but when calling system.drawing.image I have to type system.drawing.image

What is the best approach to use with issues like this? As I didnt think about framework class names when developing this application.

A: 

You could use something like:

using CmsImage = myCMS.Entities.Image;
using Image = System.Drawing.Image;

so you have a clear distinction of the two.

Or you use the fully qualified namespace like you do now, or simply rename your own Image class to 'CmsImage' if that would make sense to you, but I'd go for the first approach.

Razzie
+4  A: 

Aside from changing your entity name, your options are really limited to name-aliasing and/or fully-qualifying the two colliding names, as you are already doing.

My personal preference would be fully-qualifying both type names throughout the source. Your current approach is a mix of both aliasing and qualifying. You can also alternatively alias both types to something like:

using EntityImage = myCMS.Entities.Image;
using DrawingImage = System.Drawing.Image;
Franci Penov
As a dirty fix this is a good option, but I also agree with Mark that is how I should have approached it. Because I use code generation, via code smith, I always try to make the tables which create the entities very descriptive, but looks like I need to include a further level of description when dealing with namespaces which will conflict.Thank you all for your input
JamesStuddart
I did start with the option to rename your entity name... :-)
Franci Penov
A: 

I guess the only time you need to specify namespace-qualified type name is when you create an instance of that type. Hence, var is your friend:

var cmsImage = new myCms.Entities.Image();
var drawingImage = new System.Drawing.Image();

Aliases created with using are very hard to follow, from my experience, and they make code less clear.

Anton Gogolev
A: 

I think it would be best to use them with their full names, including namespaces. This way, when someone else or future you looks at the code, there will be no confusions.

erelender
+1  A: 

Although it is a bit painful, the best strategy is to avoid possible name conflicts. In your case you can't very well rename System.Drawing.Image, so if at all possible, consider renaming your Image type to something that is more specific to your object model (perhaps CmsImage or ImageEntity).

It is an explicit rule in the .NET Design Guidelines:

Do not give types names that would conflict with any type in the core namespaces.

Obviously, you don't have to follow those rules, but in general, I find that they offer good advice.

Mark Seemann