小编Ruf*_*art的帖子

如何使用 System.Formats.Asn1.AsnReader

2020 年 6 月起, .net实施了ASN1 阅读器文档中没有示例如何使用它。此外,在 Google 和 SO 中的搜索没有显示任何示例或描述。我在哪里可以找到一些?

c# asn.1

5
推荐指数
1
解决办法
2681
查看次数

如何向CodeContracts证明IEnumerable <T> .Single()永远不会返回null?

我有以下代码片段:

    public static string returnString()
    {
        string[] stringList = { "a" };

        if (stringList.Count() != 1)
        {
            throw new Exception("Multiple values in list");
        }

        var returnValue = stringList.Single();

        Contract.Assert(returnValue != null, "returnValue is null");

        return returnValue;
    }
Run Code Online (Sandbox Code Playgroud)

CodeContract说:

CodeContracts:断言未经证实.你是否在静态检查器不知道的Single上做了一些假设?

在我的理解中,Single()永远不会返回null - 它返回IEnumerable的唯一值或者抛出异常.如何向代码分析器证明这一点?

c# code-contracts

4
推荐指数
1
解决办法
120
查看次数

标签 统计

c# ×2

asn.1 ×1

code-contracts ×1