Sam Holder
Sam Holder

Reputation: 32936

FXCop violation CA1716 IdentifiersShouldNotMatchKeyword

We have recently started using FxCop on our code base and I am in the process of evaluating the problems. One is the IdentifiersShouldNotMatchKeywords issue. This applies to a namespace company.blah.Event, which it wants me to change to something else as event is a keyword. The docs say:

When to Suppress Warnings Do not suppress a warning from this rule. The library might not be usable in all available languages in the .NET Framework.

under what circumstances might it not be available? Do I need to change this? I imagine that it is not going to be very popular.

Upvotes: 3

Views: 1811

Answers (2)

Hans Passant
Hans Passant

Reputation: 941217

Well, it is a bit of a screwy message. It proclaims to know what the keywords will be in an as-yet unwritten language. For all you know, a future language like BrainFart may use Acme as a keyword, and you're screwed because that happens to be your company name.

There is a notable difference between the Acme and Event keywords though. The author of the BrainFart language will point out that you should have known about Event being a problem from running your code through FxCop. She'll win that argument.

You'd better change it.

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630349

Different languages have different keywords. For example I can use If as a variable in C#, but if someone loads up the project in VB, they're screwed, any case like that can cause problems.

I'd change it, just to be safe. I'd say you need to change it if anyone else is consuming your library, you can't know what language they're going to use when doing so.

Upvotes: 7

Related Questions