-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
FeatureReference.cs
38 lines (33 loc) · 1.08 KB
/
FeatureReference.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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Http.Features
{
public struct FeatureReference<T>
{
private T _feature;
private int _revision;
private FeatureReference(T feature, int revision)
{
_feature = feature;
_revision = revision;
}
public static readonly FeatureReference<T> Default = new FeatureReference<T>(default(T), -1);
public T Fetch(IFeatureCollection features)
{
if (_revision == features.Revision)
{
return _feature;
}
_feature = (T)features[typeof(T)];
_revision = features.Revision;
return _feature;
}
public T Update(IFeatureCollection features, T feature)
{
features[typeof(T)] = feature;
_feature = feature;
_revision = features.Revision;
return feature;
}
}
}