Using [NotNull] for a method's parameters

后端 未结 2 1081
离开以前
离开以前 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-03 20:27

    The only attribute that can cause the compiler to generate an error is the ObsoleteAttribute. It is because this attribute's behavior is hard-coded into the compiler.

    Attributes like the NotNull attribute are generally meant for tools (like ReSharper) to generate warnings or errors while writing code. Please read about this particular attribute here.

    You can also use tools like PostSharp to issue additional build-time errors.

提交回复
热议问题