Using [NotNull] for a method's parameters

后端 未结 2 1082
离开以前
离开以前 2021-02-03 20:01

Consider this code from ASP.NET MVC\'s source code:

public static IApplicationBuilder UseMvc(
            [NotNull] this IApplicationBuilder app,
            [No         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-02-03 20:35

    If you wish to move Null checks to be implemented by aspects and not need to be done by hand. The clear solution is to use Fody the open source build weaver. Specifically you want to leverage the NullGuard Fody

    PM> Install-Package NullGuard.Fody

    Should be everything required to get set up to use Fody with null guards. The documentation shows how you can have fine grain control if you desire.


    2019 Update

    C# 8 and .NET Core 3.0 permanently eliminate null reference exceptions.

    Tutorial: Migrate existing code with nullable reference types

    Tutorial: Express your design intent more clearly with nullable and non-nullable reference types

提交回复
热议问题