-
Notifications
You must be signed in to change notification settings - Fork 29
/
NullableContext.cs
40 lines (34 loc) · 1.23 KB
/
NullableContext.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
using Mono.Cecil;
using System;
using System.Collections.Generic;
namespace PublicApiGenerator
{
// https://github.com/dotnet/roslyn/blob/master/docs/features/nullable-metadata.md#nullablecontextattribute
internal class NullableContext
{
[ThreadStatic]
private static Stack<ICustomAttributeProvider> _nullableContextProviders;
private static Stack<ICustomAttributeProvider> NullableContextProviders
{
get
{
if (_nullableContextProviders == null)
_nullableContextProviders = new Stack<ICustomAttributeProvider>();
return _nullableContextProviders;
}
}
internal static IDisposable Push(ICustomAttributeProvider provider) => new PopDisposable(provider);
internal static IEnumerable<ICustomAttributeProvider> Providers => NullableContextProviders;
private sealed class PopDisposable : IDisposable
{
public PopDisposable(ICustomAttributeProvider provider)
{
NullableContextProviders.Push(provider);
}
public void Dispose()
{
NullableContextProviders.Pop();
}
}
}
}