dotnetnoob
dotnetnoob

Reputation: 11330

Enum naming to avoid name clashes

I'm trying to standardise the way I name things, but as a newbie I always seem to come up with an issue somewhere further down the line.

Case in point - I have a user control and enum that clash. The UC is very specific and contains a form dropdownlist/validation for customer input - the name relates to the type of input so the class is named EmploymentStatus.

However, the dropdownlist is populated via an enum - ideally this would be called EmploymentStatus too as I've adopted the recommended singular form for enums.

No doubt everyone has come across this issue at some point, but what is a good solution?

Upvotes: 1

Views: 65

Answers (1)

Crab Bucket
Crab Bucket

Reputation: 6277

I think namespaces would be the way to go here. Just put the enum in a separate namespace then refer to fully qualified e.g.

MyCompany.MyApplication.AnotherNamespacePart.EmploymentStatus

If this is a bit verbose then you can use namespace aliases to make things a bit more readable.

using myEnum = MyCompany.MyApplication.AnotherNamespacePart;

... some code

myEnum.EmploymentStatus

Please note I've assumed C# here but the principle will hold for other asp.net languages

In my humble opinion and all that

Upvotes: 2

Related Questions