简体   繁体   中英

How to resolve Code Analysis - CA1720 for GUID datatype

CA1720 for datatype GUID, Warning shown as follows:

CA1720 Identifiers should not contain type names In member 'ABCService.GetReport(Guid)', consider replacing the data type identifier 'GUID' in parameter name 'reportGUID' with a more generic term, such as 'value'.

How to handle GUID datatype?

From MSDN

If fired against a parameter: Replace the data type identifier in the name of the parameter with either a term that better describes its meaning or a more generic term, such as 'value'.

If fired against a member: Replace the language-specific data type identifier in the name of the member with a term that better describes its meaning, a language-independent equivalent, or a more generic term, such as 'value'.

Simply use a classic Id, Uid, UniqueIdentifier, ... and not Guid.

Suppress the rule if you think it's important or if the library have been previous shipped

[SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames")]

reportGUID contains guid in its name. The rule says you should remove it from the name of the parameter.

Do provide a name that is related to the meaning of the parameter, not its type. One solution would be reportID .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM