简体   繁体   English

CA 1822 WEB API

[英]CA 1822 WEB api

I'm using the .NET WebAPI for creating RESTful services. 我正在使用.NET WebAPI创建RESTful服务。 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. CA1822:Microsoft.Performance:永远不会使用“ LoginController.Post(Credential)”的“ this”参数(或Visual Basic中的“ Me”)。 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. 将成员标记为静态成员(或在Visual Basic中为Shared),或者在方法主体或至少一个属性访问器中使用“ this” /“ Me”(如果适用)。 C:\\Workspace\\Services\\SriLankan.Mobility.Services\\Controllers\\LoginController.cs 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. 我不能只是使POST方法成为静态方法,因为这样框架就无法映射请求。

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). 更正代码-确保不需要引用“ this”(警告试图帮助您避免不必要的空检查)。 Probably not applicable in your case. 可能不适用于您的情况。 [see CA1822: Mark Members as Static http://msdn.microsoft.com/en-us/library/ms245046.aspx] [请参阅CA1822:将成员标记为静态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] 禁止显示警告[请参见源禁止概述中的http://msdn.microsoft.com/zh-cn/library/ms244717.aspx]

HTH 高温超导

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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