I have a class which starts off something like this:
namespace Tools.Builders
{
internal abstract class Builder
{
[SuppressMessage("Microsoft.Maintainability", "CA1502")]
private static readonly Dictionary<string, Func<ILogger, Builder>> _builders =
new Dictionary<string, Func<ILogger, Builder>>
{
{ "1", (x) => {return new BuilderType1(x);} },
{ "2", (x) => {return new BuilderType2(x);} },
{ "3", (x) => {return new BuilderType3(x);} },
{ "4", (x) => {return new BuilderType4(x);} },
{ "5", (x) => {return new BuilderType5(x);} },
{ "6", (x) => {return new BuilderType6(x);} },
{ "7", (x) => {return new BuilderType7(x);} },
{ "8", (x) => {return new BuilderType8(x);} },
{ "9", (x) => {return new BuilderType9(x);} },
};
protected ILogger _logger;
protected Builder(ILogger logger)
{
_logger = logger;
}
//...
This causes a CA1502 warning of the form "Builder.Builder() has a cyclomatic complexity of..." (which is a known problem with this sort of initialiser). However my problem is I can't suppress the warning. I've tried putting the SuppressMessageAttribute in all sorts of different places in the code, but it just gets ignored. Any suggestions anyone?