Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReSharper complains about uppercase "ID" in member "EntityID"

I have a property "EntityID" in a class. Resharper (5.1) says

Name 'EntityID' does not match rule 'Methods, properties and events'. Suggested name is 'EntityId'.

But IMHO according to the naming conventions in the Design Guidelines for Class Library Developers. 'EntityID' should be perfectly fine:

  • Do not use acronyms that are not generally accepted in the computing field.
  • Where appropriate, use well-known acronyms to replace lengthy phrase names. For example, use UI for User Interface and OLAP for On-line Analytical Processing.
  • When using acronyms, use Pascal case or camel case for acronyms more than two characters long. For example, use HtmlButton or htmlButton. However, you should capitalize acronyms that consist of only two characters, such as System.IO instead of System.Io.
  • Do not use abbreviations in identifiers or parameter names. If you must use abbreviations, use camel case for abbreviations that consist of more than two characters, even if this contradicts the standard abbreviation of the word

*Update: * The latest version of the guidelines also say:

Do capitalize both characters of two-character acronyms, except the first word of a camel-cased identifier. A property named DBRate is an example of a short acronym (DB) used as the first word of a Pascal-cased identifier. A parameter named ioChannel is an example of a short acronym (IO) used as the first word of a camel-cased identifier.

Am I understanding the guidelines correctly? If so, how can I make ReSharper accept "EntityID" (well known two letter acronym) but reject "HTMLReader" (it should be HtmlReader).

like image 733
bitbonk Avatar asked Jul 28 '10 08:07

bitbonk


2 Answers

If you wish ReSharper to have "ID" as a valid abbreviation for "Identity" then simply select the Property, press "Alt-Enter" and then select "Add 'ID' to the abbreviations list" from the ReSharper context-menu.

like image 52
Tim Lloyd Avatar answered Oct 07 '22 16:10

Tim Lloyd


Do you want to stick to the recommendations of the Framework Design Guidelines, or do you want to use uppercase ID regardless?

The latest version of the guidelines has this to say:

The two abbreviations that can be used in identifiers are ID and OK. In Pascal-cased identifiers they should appear as Id, and Ok. If used as the first word in a camel-cased identifier, they should appear as id and ok, respectively.

So it seems that ReSharper is correct in the case of Id.

Out of interest, ReSharper also recommends that two character acronyms follow the same casing rules. This is at odds with the guidelines: "Do capitalize both characters of two-character acronyms, except the first word of a camel-cased identifier."

like image 20
LukeH Avatar answered Oct 07 '22 16:10

LukeH