Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit e5b3a72

Browse files
committed
Add FeatureReference back
1 parent fdb3d54 commit e5b3a72

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace Microsoft.AspNet.Http.Features
5+
{
6+
public struct FeatureReference<T>
7+
{
8+
private T _feature;
9+
private int _revision;
10+
11+
private FeatureReference(T feature, int revision)
12+
{
13+
_feature = feature;
14+
_revision = revision;
15+
}
16+
17+
public static readonly FeatureReference<T> Default = new FeatureReference<T>(default(T), -1);
18+
19+
public T Fetch(IFeatureCollection features)
20+
{
21+
if (_revision == features.Revision)
22+
{
23+
return _feature;
24+
}
25+
_feature = (T)features[typeof(T)];
26+
_revision = features.Revision;
27+
return _feature;
28+
}
29+
30+
public T Update(IFeatureCollection features, T feature)
31+
{
32+
features[typeof(T)] = feature;
33+
_feature = feature;
34+
_revision = features.Revision;
35+
return feature;
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)