2017-01-09 48 views
1

在我的项目中,有一些编码需要遵循Web Api。 有没有什么办法可以在Resharper中配置这些指令?我正在使用Resharper旗舰版。我们也可以这样配置resharper,如果这些指令没有遵循,那么它会抛出一个错误并显示建议。使用Resharper实现编码指南

该准则包含像普通的指令:

Use Camel case in Payload 
    Use camel case for the data elements in the payload. Eg:firstName,lastName                                     
Use lowercase in Endpoints 
    Use only lower case when defining the endpoints.     
    Eg: GET \api\v1\customers\{CustomerID}\rewards                 

Use hyphen for compound words in Endpoints 
    Use hyphen for compound words in Endpoints.     
    Eg: GET \api\v1\customers\{CustomerId}\order-history  

Use Nouns not verbs 
    Noun based endpoint should be used rather than verb based endpoint for CRUD operations.            
    Eg:  GET \api\v1\\customers, GET \api\v1\customers\{CustomerID}               
      GET \api\v1\GetAllCustomers 

Use verb followed by noun in case of certain functions.          
    Eg: PUT \api\v1\customers\{CustomerID}\send-email 
+0

谢谢大家的快速回复。但我需要更多的定制。 例如如果有人将端点定义为captial case letter [Route(“Seller/Search/{Page}/{PageSize}”)],那么它应该抛出错误并建议将[i]作为[Route(“seller/search/{page}/{ pageSize}“)] – SKiran

回答

0

如果您打开ReSharper的选项菜单在Visual-Studio中,您可以配置这样的事情。如果您滚动到选项列表的底部,您可以找到支持的每种语言的不同节点。例如,您可以配置大写,小写或布拉斯布局。该屏幕截图显示了C#的一些约定。 enter image description here

我不知道启用错误通知的方式。但是有一个快捷方式使用您的配置样式为整个文件(在我的情况下,Strg + E + F)。所以如果有人没有使用你的约定,并且你打开了他的一个班级,你只需按下组合键,文件就会被设置。也许这也可以通过Jenkins或者某些东西集成到Build-Processes中。但我还没有尝试过。

如果您使用了Resharper-> Manage Options,则可以将新设置导出为文件。你的同事可以用与你导出相同的方式导入这些设置。

我希望这对你有帮助。

+0

感谢您的帮助。 – SKiran

1

我相信你正在寻找StyleCop,以及它的Resharper插件。 StyleCop“分析C#源代码以强制执行一组样式和一致性规则”,包括您可以自己编写的规则。

https://github.com/StyleCop

+0

感谢您的帮助。这可以通过使用StyleCop编写自定义规则来实现https://github.com/Visual-Stylecop/Visual-StyleCop/wiki/Authoring-a-Custom-StyleCop-Rule – SKiran