Is it possible to detect unreachable code or other built-in compilation warnings using Roslyn

Is it possible to detect unreachable code or other built-in compilation warnings using Roslyn?

private void DoSomething()
{
     string a = "TEST";

     throw new Exception("Why would I throw an exception here?");

     a = "This will never be reached"; //this is a compile time warning for unreachable code...Can I detect it?

}

I tried to examine the properties of node in semantics and syntax methods, but did not see any problems or collections of warnings.

+3
source share
1 answer

, AnalyzeRegionControlFlow. , , . AnalyzeRegionControlFlow , RegionEndPointIsReachable, , , .

, , , GetDiagnostics .

+7

All Articles