0

I am developing some async code using Web Api, and I get a lot of FxCop errors that I would like to suppress. For example the following code in my controller would trigger these errors:

  1. UsePropertiesWhereAppropriate
  2. MarkMembersAsStatic
  3. DoNotNestGenericTypesInMemberSignatures
public Task<HttpResponseMessage<IEnumerable<Foo>>> GetAsync()
{
}

I do not want to suppress these rules for the whole assembly, so it seems like the only way to suppress the errors in code is to add a SuppressMessage attribute for each violated rule on each method. Is there a better way to suppress the errors? I am thinking of custom FxCop rules... Is it possible to create a rule like "Ignore DoNotNestGenericTypesInMemberSignatures for Task<T>" or "Ignore these rules for any type inheriting from Bar class"?

Andrew Bezzub
  • 15,744
  • 7
  • 51
  • 73

2 Answers2

1

No, there is no way to get any of the Microsoft-provided rules to conditionally ignore certain types or members like this. You have three basic choices:

  1. Suppress each violation individually,
  2. Disable the rules entirely for the assemblies containing the "special" types, or
  3. Disable the Microsoft-provided rules, but provide alternate custom rules that are able to ignore your types.

Personally, I would opt for #1, but ymmv...

Nicole Calinoiu
  • 20,843
  • 2
  • 44
  • 49
0

I believe the closest answer for this is Custom Rule in FxCop to only apply to methods called by particular type's method ? Hopefully, that works for you, otherwise I would say the answer is no

Community
  • 1
  • 1
Justin Pihony
  • 66,056
  • 18
  • 147
  • 180