Reputation: 114
I want to change inspection severity for one case
Say i have an enum
enum MyEnum { First, Second, Third }
and then a switch
void Foo(MyEnum value)
{
// Looking for something like
// Resharper once severity:error SwitchStatementMissingSomeCases
switch (value)
{
case MyEnum.First:
// do something
break;
case MyEnum.Second:
// do something else
break;
// <<< Missing MyEnum.Third
default:
throw new ArgumentOutOfRangeException();
}
}
I want this code to produce a compilation error. Is it possible?
I understand it is possible to do something like code below, but i want to know there is a missing case at compile time
void Bar()
{
// do something
}
void Baz()
{
// do something else
}
Dictionary<MyEnum, Action> Handlers = new Dictionary<MyEnum, Action>
{
[MyEnum.First] = Bar
[MyEnum.Second] = Baz
}
void Foo(MyEnum value)
{
if (! Handlers.TryGetValue(value, out Action action))
throw new ArgumentOutOfRangeException();
action();
}
UPD: I don't want to set global inspection severity
UPD2 I have like 50 switches (on other enums) where missing case is not a big deal and just a couple of switches where missing case should be a compilation error. It's possible to set global level to error and disable error 50 times, but... a bit ugly
UPD3 Unfortunately there is no way to do it now (22.05.2018) Comment 1 Comment 2
Upvotes: 1
Views: 254
Reputation: 114
Unfortunately there is no way to do it now (22.05.2018) with simple comment
Upvotes: 1
Reputation: 1691
If I understood you correctly, you just have to click on the Resharper bulb and configure it to add the missing cases and the severity (Error),
Upvotes: 0