I have two method overloads:
bool HasRight(RightType rightType, string cityId);
bool HasRight(RightType rightType, string cityAlias);
Of course it won't compile as methods signatues are the same. What is the best way to solve naming problem in this case?
Use different method names, don't misuse overloading for semantically-disconnected things.
For example:
bool HasRightById(RightType rightType, string cityId);
bool HasRightByAlias(RightType rightType, string cityAlias);
Would you immediately be able to distinguish between an id and an alias? How about simply:
bool HasRight(RightType rightType, string cityIdOrAlias)
If it isn't clear cut, something like "if it starts with :, for example :nyc, then it is an id, else it is assumed to be an alias". Other options:
suffixed names:
bool HasRightById(RightType rightType, string cityId)
bool HasRightByAlias(RightType rightType, string cityAlias)
take both and demand exactly one inside the method:
bool HasRight(RightType rightType, string cityId, string cityAlias)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With