You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unofficial code analyzers for CSharpFunctionalExtensions. This project aims to provide code analyzers to identify potential issues or misuse of the Result object from the CSharpFunctionalExtensions library.
Features
Identifies scenarios where the IsSuccess property is not checked before accessing the Value.
Verifies that logic is terminated when IsFailure is true before before accessing the Value.
Supports a variety of control flow structures, including if statements, ternary operators, and now C# switch expressions.
Getting Started
To install the analyzers, you can add the NuGet package to your project:
Here are some examples to show what this analyzer can catch.
Example 1: Accessing Value without checking IsSuccess
publicvoidDoSomething(Result<int>result){varx=result.Value;// Analyzer will report a warning here}
Example 2: Using IsSuccess in Switch Expressions
publicIActionResultProcessResult(Result<int>result){returnresultswitch{{Error:varerr}whenerr==Error.NotFound=>NotFound(),
_ =>Ok(result.Value)// Analyzer will report a warning here};}
Example 3: Not breaking out when IsFailure is true
publicvoidDoSomething(Result<int>result){if(result.IsFailure){// logic here}varx=result.Value;// Analyzer will report a warning here}
Will be fixed if you return ;
publicvoidDoSomething(Result<int>result){if(result.IsFailure){return}varx=result.Value;// Analyzer will report a warning here}