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.
- Identifies scenarios where the IsSuccessproperty is not checked before accessing theValue.
- Verifies that logic is terminated  when IsFailureis true before before accessing theValue.
- Supports a variety of control flow structures, including ifstatements, ternary operators, and now C# switch expressions.
To install the analyzers, you can add the NuGet package to your project:
Install-Package CSharpFunctionalExtensions.AnalyzersHere are some examples to show what this analyzer can catch.
public void DoSomething(Result<int> result)
{
    var x = result.Value;  // Analyzer will report a warning here
}public IActionResult ProcessResult(Result<int> result)
{
    return result switch
    {
        { Error: var err } when err == Error.NotFound => NotFound(),
        _ => Ok(result.Value)  // Analyzer will report a warning here
    };
}public void DoSomething(Result<int> result)
{
    if (result.IsFailure)
    {
        // logic here
    }
    var x= result.Value; // Analyzer will report a warning here
}Will be fixed if you return ;
public void DoSomething(Result<int> result)
{
   if (result.IsFailure)
   {
       return
   }
   var x= result.Value; // Analyzer will report a warning here
}See changelog
Contributions are welcome! Please feel free to open an issue or submit a pull request.
MIT