0

I have an ITemplate interface in my project. All interfaces derived from it have names that do not start with I. This causes the InconsistentNaming warning to appear.

I want to suppress this warning for all interfaces derived from the ITemplate interface.

I know about SuppressMessage attribute, but it does not suppress warnings on the derived types. I tried to play around with Scope property of this attribute, but unfortunately nothing changed.

Basically, I want to do something like this:

[SuppressMessage("ReSharper", "InconsistentNaming", Target = Targets.Inheritors)]
public interface ITemplate;
2
  • 1
    You should be able to right click on the warning and suppress it. I'm not sure why you can't just use a class instead of another interface. Personally, I prefer the I prefix for interface names and most people that read your code will know what that means. But that's up to you I guess. Commented Jul 6, 2024 at 18:04
  • @JonathanWood I also use the I prefix for the interfaces, but interfaces derived from ITemplate are used only through reflection in my project, and their names is important. I can't use abstract classes because some templates must be derived from more than one other template Commented Jul 6, 2024 at 18:33

1 Answer 1

2

There is no way to suppress the Inconsistent Naming warning only for types deriving from a specific interface. There are a couple of other options.

pragma IDE1006

Use the pragma directive to suppress the warning within in an entire file. Place the following at the top of the file:

#pragma warning disable IDE1006 // Inconsistent naming

To re-enable the warning anywhere else in the file, add the following just above where the warning should be re-enabled:

#pragma warning restore IDE1006 // Inconsistent naming

.csproj NoWarn

To suppress the warning for an entire project, use the NoWarn property. Open up the .csproj in question and add the following:

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

  <PropertyGroup>
    <!-- Other properties -->
    <NoWarn>$(NoWarn);IDE1006</NoWarn>
  </PropertyGroup>

  <!-- Other project settings -->

</Project>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer, but I want to suppress this warning forever, and not for the entire project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.