简体   繁体   English

插入字符串c#6.0和Stylecop

[英]Interpolate string c# 6.0 and Stylecop

I am using Stylecop version : 4.7.49.0 我使用的是Stylecop版本:4.7.49.0

Has anyone used the latest interpolate string functionality in c# 6.0 有没有人在c#6.0中使用过最新的插值字符串功能

example

var totalUnits = GetUnitsGetTotalIssuedShares(myId);
var testString = $"Test Units :{totalUnits}, have been shipped.";

When I build i get the stylecop error SA0102 - because stylecop cant parse the file. 当我构建我得到了stylecop错误SA0102 - 因为stylecop无法解析文件。 It doesn't seem like there is a new version of stylecop that can handle 6.0 yet? 似乎没有新版本的stylecop可以处理6.0了吗?

error :SA0102: A syntax error has been discovered in file 错误:SA0102:在文件中发现了语法错误

Is there anyway around this error? 反正有这个错误吗?

SA0102 is an internal stylecop error so can't be supressed or ignored via a settings file. SA0102是内部stylecop错误,因此无法通过设置文件进行抑制或忽略。

You can suppress a file from stylecop by finding the filename and changing the section to this in the csproj: 您可以通过查找文件名并在csproj中将部分更改为此来禁止来自stylecop的文件:

<Compile Include="<filename>.cs">
  <ExcludeFromStyleCop>True</ExcludeFromStyleCop>
</Compile>

You can get the same effect by right clicking on the offending file and selecting "exclude from style cop" if you have the StyleCop plugin installed. 如果安装了StyleCop插件,右键单击有问题的文件并选择“从样式警察中排除”可以获得相同的效果。 It currently needs to be 4.7.50 alpha for Visual Studio 2015. 它目前需要为Visual Studio 2015的4.7.50 alpha。


The more modern way of doing this is to make use of the Analyzers feature of Visual Studio 2015, with StyleCop.Analyzers . 更现代的方法是使用StyleCop.Analyzers的Visual Studio 2015的分析器功能。

在此输入图像描述

Moving to Stylecop.Analyzers, this would add them into the rules in the relevant *.ruleset file (same place as CodeAnalysis rules) 转到Stylecop.Analyzers,这会将它们添加到相关* .ruleset文件中的规则中(与CodeAnalysis规则相同的位置)

在此输入图像描述

and you can run them via 你可以通过它来运行它们

在此输入图像描述

Which has the same effect as right click Run StyleCop : 这与右键单击Run StyleCop具有相同的效果:

Ie giving: 即给:

在此输入图像描述

This will have better support for C# 6, as StyleCop 4.7.50, which Supports Visual Studio 2015, is in alpha and does not yet support C# 6. 这将更好地支持C#6,因为支持Visual Studio 2015的StyleCop 4.7.50是alpha版本,但尚不支持C#6。

StyleCop should be able to handle C# 6 now: StyleCop现在应该能够处理C#6:

Changes Beta 4.7.51: Added initial (and untested) support for C# 6.0 syntax 更改Beta 4.7.51:添加了对C#6.0语法的初始(和未经测试)支持

So with stable build 4.7.54 or later you should not encounter this anymore: http://stylecop.codeplex.com/releases/view/621306 因此,使用稳定版本4.7.54或更高版本,您不应再遇到此问题: http ://stylecop.codeplex.com/releases/view/621306

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

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