Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Resharper声明如果/else条件永远不会被命中,为什么?_C#_C# 4.0_Visual Studio 2015_Resharper - Fatal编程技术网

C# Resharper声明如果/else条件永远不会被命中,为什么?

C# Resharper声明如果/else条件永远不会被命中,为什么?,c#,c#-4.0,visual-studio-2015,resharper,C#,C# 4.0,Visual Studio 2015,Resharper,我有一个PushSharp示例中的代码,该示例详细说明了如何处理异常。由于某种原因,所有的else条件都被Resharper灰显,表示表达式总是false。我不明白这怎么可能 // ex is an Exception passed in to the method if (ex is NotificationException) { // Deal with the failed notification var notification = ((NotificationExc

我有一个PushSharp示例中的代码,该示例详细说明了如何处理异常。由于某种原因,所有的
else
条件都被Resharper灰显,表示
表达式总是false
。我不明白这怎么可能

// ex is an Exception passed in to the method
if (ex is NotificationException)
{
    // Deal with the failed notification
    var notification = ((NotificationException)ex).Notification;
    var logItem = new PushLog($"{typePrefix} Notification failed", $"Notification Failed: {notification}");
    _pushLogRepo.Insert(logItem);
}
else if (ex is DeviceSubscriptionExpiredException) // Resharper says this is always false
{
   // exception handling code...
}
else if (ex is RetryAfterException) // Resharper says this is always false
{
   // exception handling code...
}
else
{
    Console.WriteLine("Notification Failed for some (Unknown Reason)");
}
有人能解释一下这是怎么可能的吗?我不明白怎么会这样。这是一个VS2015的屏幕截图,它有一点清晰的语法高亮-忽略错误,我处于重构的中间。

如果这些类继承了
NotificationException
,就会发生这种情况,因为第一个分支总是会命中。

[Bangs head]当然。你说得对。我应该注意到这一点。证明:。谢谢,传递的是哪种例外情况?什么在传递它?它是一个普通的旧
异常
。它是由我正在使用的库提供的错误处理方法提供的。该库可能只引发某种类型的异常,即使它是以泛型形式出现的。或者它可能是一个重拾器错误。谁知道呢。是的,Slaks得到了它-它只抛出从基类派生的异常,第一个
if
语句捕获了基类,因此出现了问题。C#101。应该发现的。