Domanda

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?

È stato utile?

Soluzione

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")]

Altri suggerimenti

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.

Add [NoWarn] on the *.csproj file to disable it.

  <PropertyGroup>
    <NoWarn>$(NoWarn);CA1720</NoWarn>
    .....
  </PropertyGroup>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top