插入字符串 c# 6.0 和 Stylecop [英] Interpolate string c# 6.0 and Stylecop

查看:20
本文介绍了插入字符串 c# 6.0 和 Stylecop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Stylecop 版本:4.7.49.0

有没有人在 c# 6.0 中使用过最新的内插字符串功能

示例

var totalUnits = GetUnitsGetTotalIssuedShares(myId);var testString = $"测试单元:{totalUnits},已发货.";

当我构建时,我收到 stylecop 错误 SA0102 - 因为 stylecop 无法解析文件.好像还没有可以处理 6.0 的新版本 stylecop?

<块引用>

错误:SA0102:在文件中发现语法错误

无论如何解决这个错误?

解决方案

SA0102 是一个

移至 Stylecop.Analyzers,这会将它们添加到相关 *.ruleset 文件中的规则中(与 CodeAnalysis 规则位于同一位置)

你可以通过

运行它们

与右键单击Run StyleCop具有相同的效果:

即给予:

这将更好地支持 C# 6,因为支持 Visual Studio 2015 的 StyleCop 4.7.50 处于 alpha 阶段,尚不支持 C# 6.

I am using Stylecop version : 4.7.49.0

Has anyone used the latest interpolate string functionality in 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. It doesn't seem like there is a new version of stylecop that can handle 6.0 yet?

error :SA0102: A syntax error has been discovered in file

Is there anyway around this error?

解决方案

SA0102 is an internal stylecop error so can't be supressed or ignored via a settings file.

You can suppress a file from stylecop by finding the filename and changing the section to this in the csproj:

<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. It currently needs to be 4.7.50 alpha for Visual Studio 2015.


The more modern way of doing this is to make use of the Analyzers feature of Visual Studio 2015, with StyleCop.Analyzers.

Moving to Stylecop.Analyzers, this would add them into the rules in the relevant *.ruleset file (same place as CodeAnalysis rules)

and you can run them via

Which has the same effect as right click Run StyleCop:

I.e. 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.0 和 Stylecop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆