Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Visual Studio Warning – Prefix 'S_' or 'T_' is not expected

Whenever I create many constants for different purposes in a project, I tend to categorize them by putting a one letter prefix and an underscore in front of the names. Now, I chose the prefix T_ for some constants and noticed that the compiler gave me a warning:

IDE1006: Naming rule violation: Prefix 'T_' is not expected

That made me really curious, since I have no naming rule configured that says anything about that prefix, so I experimented a little. This warning only shows for the letters S and T, both uppercase and lowercase, so other prefixes like A_, b_ or Z_ are allowed. I tried this with local variables, properties, constants, methods and classes, and for all those cases, this rule applies: No uppercase or lowercase T_ or S_ at the start of an identifier. I know there are many cases I didn’t test, but I’m pretty sure this is consistent across all sorts of identifiers in C#.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Now the question is, why is that? Are the prefixes T_, t_, S_, s_ used for anything specific internally, or is it a general naming convention that I simply don’t know anything about?

I already googled for the specific message about the prefix, or the prefix in general, and I also took a very brief look at the documentation of IDE1006. None of those things yielded any answers.

Since it was requested, here’s my .editorconfig:

[*.cs]

# IDE0039: Use local function
dotnet_diagnostic.IDE0039.severity = silent

As you can see, there is nothing naming related here.

And here’s my .csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

PS: I know using underscores in identifiers is sort of frowned upon, the reason I use them is because I name my constants in capslock, which, I think, is also frowned upon? I do that because I prefer having a clear indication of what’s a constant and what isn’t.

>Solution :

Are the prefixes T_, t_, S_, s_ used for anything specific

Quote the coding conventions manual:

When working with static fields that are private or internal, use the s_ prefix and for thread static use t_.

public class DataService
{
   private static IWorkerQueue s_workerQueue;

   [ThreadStatic]
   private static TimeSpan t_timeSpan;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading