简体   繁体   中英

CA 1822 WEB api

I'm using the .NET WebAPI for creating RESTful services. However, I'm getting the following warning when running the code analysis:

CA1822 : Microsoft.Performance : The 'this' parameter (or 'Me' in Visual Basic) of 'LoginController.Post(Credential)' is never used. Mark the member as static (or Shared in Visual Basic) or use 'this'/'Me' in the method body or at least one property accessor, if appropriate. C:\\Workspace\\Services\\SriLankan.Mobility.Services\\Controllers\\LoginController.cs

Is there anyway to avoid this? I can't just make the POST method static, because then the framework is unable to map the request.

Any ideas?

You have two choices

  1. Correct the code - make sure it does not need to be referencing a 'this' (the warning is trying to help you avoid unneeded null checks). Probably not applicable in your case. [see CA1822: Mark Members as Static http://msdn.microsoft.com/en-us/library/ms245046.aspx]

  2. Suppress the warning [see In Source Suppression Overview http://msdn.microsoft.com/en-us/library/ms244717.aspx]

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM