Suggestion: ignore InconsistentNaming for parameter is prefixed with verbatim identifier, when signature has extern

From C# Language Specification, § 2.4.2 Identifiers (C#) :

> The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier.

Given this code:

[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr sass_map_set_key(IntPtr @value_map, int @index, IntPtr @key);
 
ReSharper says:
 
> Name 'value_map' does not match rule Parameters. Suggested name is 'valueMap'.
 
In fact, the value_map is depicting the name used in external C lib code.
 
Having said that, IMO:
  • It would be nice if ReSharper interpret extern and `@`-prefixed parameter as a special case and skip InconsistentNaming warning.
  • The ultimate introspection feature would be: if external library is reachable and Resharper shell out the command `Dumpbin /exports <libpath>` to export the names, inspect the names and match the casing to one defined in C# extern signature to rather suggest the exact casing used in C lib (prefixed with verbatim identifier).
2 comments
Comment actions Permalink

The parameter names for P/Invoke methods don't matter. All that matters is how the parameter values are laid out in memory when they're passed to the external method.

You could call the parameter "value_map", "valueMap", or even "Kull_The_Conqueror" if you wanted to.

0
Comment actions Permalink

> The parameter names for P/Invoke methods don't matter.

I agree. The point here is that the prefix @ is meant to indicate that the variable is associated with the foreign programming language, so user might prefer to match the casing of that language as well.

0

Please sign in to leave a comment.