Is it possible to get a warning if return value is not used?

前端 未结 1 669
半阙折子戏
半阙折子戏 2020-12-18 20:12

I have an extension method which returns a value. In this case, it should set a specific bit in a byte:

public static byte SetBit(this byte b, int bitNumber,          


        
1条回答
  •  醉梦人生
    2020-12-18 21:01

    There seems to be a Nuget Package for ReSharper Annotations.

    This includes a MustUseReturnValueAttribute:

    [MustUseReturnValue("Use the return value to...")]
    public byte Foo()
    {    
    }
    

    As @Kirk Woll pointed out in the comments, it is also possible to write a custom Roslyn Analyzer.

    0 讨论(0)
提交回复
热议问题