/
AnalyzerOptions.cs
82 lines (70 loc) · 3.08 KB
/
AnalyzerOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// 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.Linq;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Diagnostics
{
/// <summary>
/// Options passed to <see cref="DiagnosticAnalyzer"/>.
/// </summary>
public class AnalyzerOptions
{
internal static readonly AnalyzerOptions Empty = new AnalyzerOptions(ImmutableArray<AdditionalText>.Empty);
/// <summary>
/// A set of additional non-code text files that can be used by analyzers.
/// </summary>
public ImmutableArray<AdditionalText> AdditionalFiles { get; }
/// <summary>
/// A set of options keyed to <see cref="SyntaxTree"/> or <see cref="AdditionalText"/>.
/// </summary>
public AnalyzerConfigOptionsProvider AnalyzerConfigOptionsProvider { get; }
/// <summary>
/// Creates analyzer options to be passed to <see cref="DiagnosticAnalyzer"/>.
/// </summary>
/// <param name="additionalFiles">A set of additional non-code text files that can be used by analyzers.</param>
/// <param name="optionsProvider">A set of per-tree options that can be used by analyzers.</param>
public AnalyzerOptions(ImmutableArray<AdditionalText> additionalFiles, AnalyzerConfigOptionsProvider optionsProvider)
{
if (optionsProvider is null)
{
throw new ArgumentNullException(nameof(optionsProvider));
}
AdditionalFiles = additionalFiles.NullToEmpty();
AnalyzerConfigOptionsProvider = optionsProvider;
}
/// <summary>
/// Creates analyzer options to be passed to <see cref="DiagnosticAnalyzer"/>.
/// </summary>
/// <param name="additionalFiles">A set of additional non-code text files that can be used by analyzers.</param>
public AnalyzerOptions(ImmutableArray<AdditionalText> additionalFiles)
: this(additionalFiles, CompilerAnalyzerConfigOptionsProvider.Empty)
{ }
/// <summary>
/// Returns analyzer options with the given <paramref name="additionalFiles"/>.
/// </summary>
public AnalyzerOptions WithAdditionalFiles(ImmutableArray<AdditionalText> additionalFiles)
{
if (this.AdditionalFiles == additionalFiles)
{
return this;
}
return new AnalyzerOptions(additionalFiles);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}
var other = obj as AnalyzerOptions;
return other != null &&
(this.AdditionalFiles == other.AdditionalFiles ||
this.AdditionalFiles.SequenceEqual(other.AdditionalFiles, ReferenceEquals));
}
public override int GetHashCode()
{
return Hash.CombineValues(this.AdditionalFiles);
}
}
}