提交 7daf0450 编写于 作者: C CyrusNajmabadi

Validate invariant.

上级 1f684003
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable; using System.Collections.Immutable;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.FindReferences namespace Microsoft.CodeAnalysis.FindReferences
{ {
...@@ -29,6 +31,18 @@ internal struct DefinitionsAndReferences ...@@ -29,6 +31,18 @@ internal struct DefinitionsAndReferences
ImmutableArray<DefinitionItem> definitions, ImmutableArray<DefinitionItem> definitions,
ImmutableArray<SourceReferenceItem> references) ImmutableArray<SourceReferenceItem> references)
{ {
var definitionSet = definitions.ToSet();
for (int i = 0, n = references.Length; i < n; i++)
{
var reference = references[i];
if (!definitionSet.Contains(reference.Definition))
{
throw new ArgumentException(
$"{nameof(references)}[{i}].{nameof(reference.Definition)} not found in '{nameof(definitions)}'");
}
}
Definitions = definitions; Definitions = definitions;
References = references; References = references;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册