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

Commit baabf60

Browse files
committed
Remove Get and Set, just use indexer.
1 parent 40e970e commit baabf60

File tree

5 files changed

+24
-48
lines changed

5 files changed

+24
-48
lines changed

src/Microsoft.AspNet.Http.Features/FeatureCollection.cs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,29 @@ public virtual int Revision
3434

3535
public object this[[NotNull] Type key]
3636
{
37-
get { return Get(key); }
38-
set { Set(key, value); }
39-
}
40-
41-
public object Get([NotNull] Type key)
42-
{
43-
object result;
44-
return _features != null && _features.TryGetValue(key, out result) ? result : _defaults?.Get(key);
45-
}
46-
47-
public void Set([NotNull] Type key, object value)
48-
{
49-
if (value == null)
37+
get
5038
{
51-
if (_features != null && _features.Remove(key))
39+
object result;
40+
return _features != null && _features.TryGetValue(key, out result) ? result : _defaults?[key];
41+
}
42+
set
43+
{
44+
if (value == null)
5245
{
53-
_containerRevision++;
46+
if (_features != null && _features.Remove(key))
47+
{
48+
_containerRevision++;
49+
}
50+
return;
5451
}
55-
return;
56-
}
5752

58-
if (_features == null)
59-
{
60-
_features = new Dictionary<Type, object>();
53+
if (_features == null)
54+
{
55+
_features = new Dictionary<Type, object>();
56+
}
57+
_features[key] = value;
58+
_containerRevision++;
6159
}
62-
_features[key] = value;
63-
_containerRevision++;
6460
}
6561

6662
IEnumerator IEnumerable.GetEnumerator()

src/Microsoft.AspNet.Http.Features/IFeatureCollection.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,5 @@ public interface IFeatureCollection : IEnumerable<KeyValuePair<Type, object>>, I
2525
/// <param name="key"></param>
2626
/// <returns>The requested feature, or null if it is not present.</returns>
2727
object this[[NotNull] Type key] { get; set; }
28-
29-
/// <summary>
30-
/// Gets the requested feature, or null if it is not present.
31-
/// </summary>
32-
/// <param name="key"></param>
33-
/// <returns></returns>
34-
object Get([NotNull] Type key);
35-
36-
/// <summary>
37-
/// Sets the given feature, overriding the existing feature if any. If a null value is
38-
/// provided then any existing feature is removed.
39-
/// </summary>
40-
/// <param name="key"></param>
41-
/// <param name="value"></param>
42-
void Set([NotNull] Type key, object value);
4328
}
4429
}

test/Microsoft.AspNet.Http.Features.Tests/FeatureCollectionTests.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ public void AddedInterfaceIsReturned()
1313
var interfaces = new FeatureCollection();
1414
var thing = new Thing();
1515

16-
interfaces.Set(typeof(IThing), thing);
17-
18-
Assert.Equal(interfaces[typeof(IThing)], thing);
16+
interfaces[typeof(IThing)] = thing;
1917

20-
object thing2 = interfaces.Get(typeof(IThing));
18+
object thing2 = interfaces[typeof(IThing)];
2119
Assert.Equal(thing2, thing);
2220
}
2321

@@ -30,9 +28,6 @@ public void IndexerAlsoAddsItems()
3028
interfaces[typeof(IThing)] = thing;
3129

3230
Assert.Equal(interfaces[typeof(IThing)], thing);
33-
34-
object thing2 = interfaces.Get(typeof(IThing));
35-
Assert.Equal(thing2, thing);
3631
}
3732

3833
[Fact]
@@ -41,12 +36,12 @@ public void SetNullValueRemoves()
4136
var interfaces = new FeatureCollection();
4237
var thing = new Thing();
4338

44-
interfaces.Set(typeof(IThing), thing);
39+
interfaces[typeof(IThing)] = thing;
4540
Assert.Equal(interfaces[typeof(IThing)], thing);
4641

4742
interfaces[typeof(IThing)] = null;
4843

49-
object thing2 = interfaces.Get(typeof(IThing));
44+
object thing2 = interfaces[typeof(IThing)];
5045
Assert.Null(thing2);
5146
}
5247
}

test/Microsoft.AspNet.Http.Tests/QueryFeatureTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void QueryReturnsParsedQueryCollection()
1414
var features = new FeatureCollection();
1515
var request = new HttpRequestFeature();
1616
request.QueryString = "foo=bar";
17-
features.Set(typeof(IHttpRequestFeature), request);
17+
features[typeof(IHttpRequestFeature)] = request;
1818

1919
var provider = new QueryFeature(features);
2020

test/Microsoft.AspNet.Owin.Tests/OwinFeatureCollectionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class OwinHttpEnvironmentTests
1212
{
1313
private T Get<T>(IFeatureCollection features)
1414
{
15-
return (T)features.Get(typeof(T));
15+
return (T)features[typeof(T)];
1616
}
1717

1818
private T Get<T>(IDictionary<string, object> env, string key)

0 commit comments

Comments
 (0)