Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 262
Yajuvendra Vant Avatar asked Oct 25 '25 04:10

Yajuvendra Vant


2 Answers

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")]
like image 153
Cybermaxs Avatar answered Oct 26 '25 19:10

Cybermaxs


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.

like image 23
ken2k Avatar answered Oct 26 '25 18:10

ken2k