wps自动识别目录错误

C#概念 (C# CONCEPTS)

.Net SDK now incorporates rich diagnostics and code recommendations in the .NET SDK by default.

.Net SDK现在默认情况下在.NET SDK中包含了丰富的诊断和代码建议。

In the past, it’s unwilling to add new warnings to C#. Its because adding recent warnings is technically a source breaking change for users who have notifications set as errors.

过去,它不愿意向C#添加新的警告。 这是因为从技术上来说,添加最近的警告对于将通知设置为错误的用户来说是一项重大的源变更。

C# compiler uses Analysis Level to introduce warnings for these patterns in a safe way.

C#编译器使用分析级别以安全的方式为这些模式引入警告。

Analysis Level is bound to the target framework of your project except you manually change what your project targets. SDK allows you to set your analysis level, though visual studio manually.

除您手动更改项目目标外,“ 分析级别”已绑定到项目的目标框架。 通过SDK,您可以通过Visual Studio手动设置分析级别。

Example of Analysis Level 5

分析级别5的示例

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup>    <OutputType>Exe</OutputType>    <TargetFramework>netcoreapp3.1</TargetFramework><AnalysisLevel>5</AnalysisLevel>  </PropertyGroup></Project>

If you always choose to be on the highest supported analysis level by default, then specify “latest” in your project file:

如果您始终默认选择处于最高支持的分析级别,则在项目文件中指定“ 最新”

<AnalysisLevel>latest</AnalysisLevel>

If you are comfortable with “preview” .Net versions

如果您对“ 预览” .Net版本感到满意

<AnalysisLevel>preview</AnalysisLevel>

Finally, the level “none,” which means “I don’t want to see any new warnings.” It’s beneficial if you are required to update your framework, but you’re not ready to absorb current warnings yet.

最后,级别为“ 无” ,表示“ 我不想看到任何新的警告。” 如果您需要更新框架,但是还没有准备好吸收当前警告,那将是有益的。

<AnalysisLevel>none</AnalysisLevel>

警告代码示例和相关解决方案 (Examples of warning codes & relevant solutions)

CS8073 —表达式始终为真或假时 (CS8073 — when the expression is always true or false)

This new warning is ubiquitous. Consider the following code:

这个新的警告无处不在。 考虑以下代码:

public void CheckDate(DateTime dateTime){    if (dateTime == null) // warning CS8073    {        return;    }}

Datetime is of struct type & struct cannot be null. The warning message is:

日期时间为结构类型,结构不能为null。 警告消息是:

Warning CS8073: The result of the expression is always ‘false’ since the value of type ‘DateTime’ is never equal to ‘null’ of type ‘DateTime?’

警告CS8073:表达式类型的结果始终为'false',因为类型'DateTime'的值永远不会等于类型'DateTime?'的'null'。

解 (Solution)

Either remove the code or change its data type to “Datetime?” so that null is an intended value for the parameter.

删除代码或将其数据类型更改为“ Datetime?” 因此null为参数的预期值。

public void CheckDate(DateTime? dateTime) //null DateTime{    if (dateTime == null) // No Warnings    {        return;    }}

CS7023 —静态类型不允许“ as”或“ is” (CS7023 — Do not allow “as” or “is” on static types)

This next one is an excellent concise improvement:

下一个是一个非常简洁的改进:

static class ClassA{}class NonStaticClass{    bool Test(object o)    {        return o is ClassA; // CS7023    }}

Because ClassA is a static class, an instance object like “O” will never be able to be an instance of this type. Below warning will be triggered:

由于ClassA是静态类,因此“ O”之类的实例对象将永远无法成为该类型的实例。 以下警告将被触发:

Warning CS7023 The second operand of an ‘is’ or ‘as’ operator may not be static type ‘ClassA’

警告CS7023“ is”或“ as”运算符的第二个操作数可能不是静态类型“ ClassA”

解 (Solution)

Make the ClassA non-static:

使ClassA为非静态:

class ClassA{}class NonStaticClass{    bool Test(object o)    {        return o is ClassA; // No Warning    }}

CS0185 —不允许对非引用类型进行锁定 (CS0185 — Do not allow locks on non-reference types)

Locking a non-reference data type(i.e., int) does nothing because they are pass-by-value. In the past, warning popup for locking on non-reference types for simple cases like a lock(10), but until recently, the compiler does not warn you for open generics like below.

锁定非引用数据类型(即int)不会执行任何操作,因为它们是按值传递的。 过去,警告弹出窗口会针对诸如lock(10)之类的简单情况锁定非引用类型,但是直到最近,编译器才对以下类似的开放泛型不发出警告。

public class ClassA{    public static void GetValue<TKey>(TKey key)    {        lock (key) // CS0185        {        }    }static void Main()    {        GetValue(1);    }}

It’s an error because passing an int here will not lock correctly. The error will be displayed.

这是一个错误,因为在此处传递int不会正确锁定。 错误将显示。

Error CS0185 ‘TKey’ is not a reference type as required by the lock statement

错误CS0185'TKey'不是锁语句要求的引用类型

解 (Solution)

Apply generic constraints to indicate the reference types allowed for TKey.

应用通用约束以指示TKey允许的引用类型。

public class ClassA{    public static void GetValue<TKey>(TKey key) where TKey : class    {        lock (key) // no error        {        }    }}

了解有关通用约束的更多信息 (Learn more about Generic Constraints)

CA2013 —不要使用ReferenceEquals (CA2013 — Do not use ReferenceEquals)

Equality is a complex topic in .NET. Consider the code below:

平等是.NET中的一个复杂主题。 考虑下面的代码:

int int1 = 1;int int2 = 1;//warning CA2013Console.WriteLine(object.ReferenceEquals(int1, int2));

The ReferenceEquals method will always return false. We will see this warning description:

ReferenceEquals方法将始终返回false。 我们将看到以下警告说明:

Warning CA2013: Do not pass an argument with value type ‘int’ to ‘ReferenceEquals’. Due to value boxing, this call to ‘ReferenceEquals’ will always return ‘false’.

警告CA2013:请勿将值类型为'int'的参数传递给'ReferenceEquals'。 由于值装箱,对此“ ReferenceEquals”的调用将始终返回“ false”。

解 (Solution)

Either use the equality operator “==” or “object”.

使用相等运算符“ == ”或“ object ”。

int int1 = 1;int int2 = 1;// using the equality operatorConsole.WriteLine(int1 == int2);//No WarningConsole.WriteLine(object.Equals(int1, int2));

CA1831 —在适当的情况下,对字符串使用AsSpan而不是基于范围的索引器 (CA1831 — Use AsSpan instead of Range-based indexers for the string when appropriate)

class Program{    public void Test(string str)    {        ReadOnlySpan<char> slice = str[1..3]; // CA1831    }}

In the code above, it’s clear the developer means to index a string using the new range based index feature in C#. Unfortunately, this will allocate a string unless you convert that string to a span first.

在上面的代码,很明显开发商的手段指标使用新的字符串[R在C#安格基于索引功能。 不幸的是,除非您首先将该字符串转换为跨度,否则这将分配一个字符串。

Warning CA1831 Use ‘AsSpan’ instead of the ‘System.Range’-based indexer on ‘string’ to avoid creating unnecessary data copies

警告CA1831在“字符串”上使用“ AsSpan”而不是基于“ System.Range”的索引器,以避免创建不必要的数据副本

解 (Solution)

The fix is to add AsSpan calls in this case:

解决方法是在这种情况下添加AsSpan调用:

class Program{    public void Test(string str)    {        ReadOnlySpan<char> slice = str.AsSpan()[1..3]; // no warning    }}

CA2014 —请勿在循环中使用“ stackalloc” (CA2014 — Do not use “stackalloc” in loops)

The “stackalloc” keyword is great when you want to make sure the operations you are doing are easy on the garbage collector. In the past, “stackalloc” was only allowed in unsafe code, but since C# 8.0., it’s also been allowed outside of unsafe blocks.

当您要确保正在垃圾回收器上执行的操作很容易时,“ stackalloc”关键字非常有用 。 过去,仅在不安全的代码中才允许使用“ stackalloc” ,但自C#8.0。起,它也可以在不安全的块之外使用。

class ClassA{    public void Test(string str)    {        int length = 3;        for (int i = 0; i < length; i++)        {            Span<int> numbers = stackalloc int[length]; // CA2014            numbers[i] = i;        }    }}

Designating a lot on the stack can lead to the popular StackOverflow exception.

在堆栈上指定很多内容可能会导致流行的StackOverflow异常。

Warning CA2014 Potential stack overflow. Move the stackalloc out of the loop.

警告CA2014潜在的堆栈溢出。 将stackalloc移出循环。

解 (Solution)

Move “stackalloc” out of the loop.

将“ stackalloc”移出循环。

class ClassA{    public void Test(string str)    {        int length = 3;        Span<int> numbers = stackalloc int[length]; // no warning        for (int i = 0; i < length; i++)        {            numbers[i] = i;        }    }}

更多C#概念 (More C# Concepts)

Thank you for reading. Keep visiting and share this in your network. Please put your thoughts and feedback in the comments section.

感谢您的阅读。 继续访问并在您的网络中分享。 请在评论部分中输入您的想法和反馈。

Follow me on LinkedIn Instagram Facebook Twitter

跟随我的LinkedIn 的Instagram 的Facebook 的Twitter

翻译自: https://medium.com/swlh/automatically-identify-bugs-in-your-code-with-net-5-3ef803774f6

wps自动识别目录错误


http://www.taodudu.cc/news/show-6747911.html

相关文章:

  • centos升级glibc至2.18安装wps 2019
  • 从BOSCore公投WPS提案,探讨区块链社区治理新思路
  • IBM BPM WPS
  • Python的txt文件转wps
  • Windows7 简体中文旗舰版下载 (MSDN官方发布正式版原版镜像)!
  • Scrum——“鸡”和“猪”的寓言
  • Scrum中的角色:你是鸡还是猪?
  • “猪”与“鸡”的寓言
  • “鸡”和“猪”的故事
  • 鸡狗票特征和交易模式
  • 鸡与猪的争论
  • 一个外企白领的自白,让我们惊慌不已:猪和母鸡合资
  • 敏捷中的“猪”与“鸡
  • Scrum meeting当中的“鸡”和“猪”
  • Scrum里面猪和鸡的角色
  • 【Hexo】GitHub_Page绑定阿里云域名
  • 学习注意力机制【1】
  • 中学生如何提升自己的注意力
  • 注意力提示
  • 注意力机制 - 注意力提示
  • 易优cms网站友情链接,设置新窗口打开无效 Eyoucms快速入门
  • 易优EyouCMS数据库配置文件是哪个?
  • 易优cms Call to undefined function think\exception\config() Eyoucms快速入门
  • 易优cms 安装常见问题汇总 Eyoucms快速入门
  • 易优cms 修改网站 基本信息教程Eyoucms快速入门
  • eyoucms采集发布,让你轻松发布大量内容!
  • Powered by EyouCms去除 易优cms快速入门
  • eyoucms定时任务全方位解析!
  • 新款戴尔笔记本win10系统改win7 安装教程
  • win8系统笔记本装成win7

wps自动识别目录错误_使用net 5自动识别代码中的错误相关推荐

  1. access子窗体的控件vba怎么写_第37讲:VBA代码中运行错误的处理方式

    大家好,本来在这一讲要接着我们的上一讲内容讲解二师兄的成长过程之九,但之九的内容是错误的处理,为了大家能更好的掌握之九二师兄的成才内容,我们临时加入一讲专门讲解VBA中错误处理,这一讲中我重点讲一下V ...

  2. matlab检查错误 函数,检查代码中的错误和警告

    调整代码分析器消息指示标记和消息 根据您在完成 MATLAB 文件时所处的阶段,您可能需要限制代码下划线标记的使用.您可以使用步骤 1 的检查代码中的错误和警告中引用的代码分析器预设执行此操作.例如, ...

  3. 关于python语言数值操作符、以下选项错误的是 答案是_关于Python注释,以下选项中描述错误的是...

    [多选题]Python中单下划线_foo与双下划线__foo与__foo__的成员,下列说法正确的是? [单选题]关于Python语言的注释,以下选项中描述错误的是 [单选题]下面代码的输出结果是 s ...

  4. ora 00900 已编译但有错误_技术分享|万万没想到!编译错误竟然还没灭绝???

    CodeWisdom-技术分享 万万没想到!编译错误竟然还没灭绝??? 复旦大学CodeWisdom团队的代码分析和挖掘小组针对开源软件项目持续集成过程中出现的编译错误,进行了大规模的经验研究.该研究 ...

  5. 关于python字符编码以下选项中描述错误的是_关于import引用,以下选项中描述错误的是...

    [单选题]11.自动化分析仪中采用同步分析原理的是:() [单选题]以下选项中,不是Python语言合法命名的是 [单选题]下列选项中可以获取Python整数类型帮助的是 [单选题]下面代码的输出结果 ...

  6. 关于mysql叙述中错误的是什么_以下关于MySQL的叙述中,错误的是( )。_学小易找答案...

    [单选题]以下关于外键约束的描述不正确的是() [单选题]在创建视图的SQL语句中,保留字AS之后接续的是(). [单选题]按照国家标准规定,一般抽屉桌下沿距离坐面至少()左右的净空. [多选题]工作 ...

  7. 关于python语言的注释以下描述错误的是_关于 Python 注释,以下选项中描述错误的是 ( )_学小易找答案...

    [单选题]关于 Python 程序格式框架的描述,以下选项中错误的是 ( ) [简答题]2014年22JAVA_B场参考答案.doc [简答题]Java2006试卷.doc 1.请提供每题的详细分析; ...

  8. python注释语句不被解释器过滤掉_关于 Python 注释,以下选项中描述错误的是 ( )_学小易找答案...

    [单选题]关于 Python 程序格式框架的描述,以下选项中错误的是 ( ) [简答题]2014年22JAVA_B场参考答案.doc [简答题]Java2006试卷.doc 1.请提供每题的详细分析; ...

  9. 测试nginx网站代码_在40行以下代码中使用NGINX进行A / B测试

    测试nginx网站代码 by Nitish Phanse 由Nitish Phanse 在40行以下代码中使用NGINX进行A / B测试 (A/B testing with NGINX in und ...

最新文章

  1. 搜狗手机输入法php,在线调用搜狗云输入法
  2. xmindcore.java_求解Xmind问题
  3. 如何判断一个对话机器人有多智能?
  4. 全闪存存储时代 NVMe到底是什么?
  5. linux msgrcv阻塞接收_linux下高并发服务器实现
  6. 命名管道实现进程的信息传递【mkfifo函数、open函数】
  7. eclipse中配置c++开发环境 Eclipse + CDT + MinGW
  8. 高性能框架gevent和gunicorn在web上的应用及性能测试
  9. object.__比较运算__
  10. 耳挂式蓝牙耳机原理_挂耳式蓝牙耳机如何佩戴
  11. android rtc 不能写时间到 rtc 原因分析
  12. 谷歌安全研究员发现3个 Apache Web 服务器软件缺陷
  13. 继电保护原理3-输电线纵差
  14. 【性能测试】JSON工具 对比 fastjson jackson
  15. 怎么看电脑网卡是否支持5g频段
  16. APK修改神器:插桩工具 DexInjector
  17. 百度智能云携手鄂尔多斯市:大数据赋能,让房子有了身份证会说话
  18. Ctrl+26个英文字母组合的Excel快捷键,都是最常用的快捷键!
  19. 全自动生成、设置课表壁纸【完结】
  20. Linux-USB驱动笔记(五)--主机控制器驱动框架

热门文章

  1. 低宽带网络加速平台 企业用途
  2. Wannafly 挑战赛13 B- Jxc军训
  3. 双11海尔冰箱·冷柜:全网销额再创纪录居行业第一
  4. 21点代码python_python实现一个简单的21点游戏
  5. sigma-delta数字滤波器的设计(1) — 原理与前端设计
  6. 气象数据.txt读取与可视化
  7. beetl,freemarker,thymeleaf对比及springboot集成
  8. 如何用手机登录企业邮箱?微信如何绑定邮箱账号?
  9. 前向传播、反向传播与感知器
  10. 分类器的不确定度估计