/
NullableContextOptions.cs
54 lines (46 loc) · 1.75 KB
/
NullableContextOptions.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
namespace Microsoft.CodeAnalysis
{
/// <summary>
/// Represents the default state of nullable analysis in this compilation.
/// </summary>
[Flags]
public enum NullableContextOptions
{
/// <summary>
/// The nullable analysis feature is disabled.
/// </summary>
Disable = 0,
/// <summary>
/// Nullable warnings are enabled and will be reported by default.
/// </summary>
Warnings = 1,
/// <summary>
/// Nullable annotations are enabled and will be shown when APIs
/// defined in this project are used in other contexts.
/// </summary>
Annotations = 1 << 1,
/// <summary>
/// The nullable analysis feature is fully enabled.
/// </summary>
Enable = Warnings | Annotations,
}
public static class NullableContextOptionsExtensions
{
private static bool IsFlagSet(NullableContextOptions context, NullableContextOptions flag) =>
(context & flag) == flag;
/// <summary>
/// Returns whether nullable warnings are enabled.
/// </summary>
public static bool WarningsEnabled(this NullableContextOptions context) =>
IsFlagSet(context, NullableContextOptions.Warnings);
/// <summary>
/// Returns whether nullable annotations are enabled.
/// </summary>
public static bool AnnotationsEnabled(this NullableContextOptions context) =>
IsFlagSet(context, NullableContextOptions.Annotations);
}
}