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

Commit 05c476d

Browse files
committed
Merge pull request #526 from benaadams/generic-get+set
Move generic Get/Set into Interface
2 parents 364a712 + 62ec29b commit 05c476d

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ public IEnumerator<KeyValuePair<Type, object>> GetEnumerator()
9393
}
9494
}
9595

96+
public TFeature Get<TFeature>()
97+
{
98+
return (TFeature)this[typeof(TFeature)];
99+
}
100+
101+
public void Set<TFeature>(TFeature instance)
102+
{
103+
this[typeof(TFeature)] = instance;
104+
}
105+
96106
private class KeyComparer : IEqualityComparer<KeyValuePair<Type, object>>
97107
{
98108
public bool Equals(KeyValuePair<Type, object> x, KeyValuePair<Type, object> y)

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,19 @@ public interface IFeatureCollection : IEnumerable<KeyValuePair<Type, object>>
2727
/// <param name="key"></param>
2828
/// <returns>The requested feature, or null if it is not present.</returns>
2929
object this[Type key] { get; set; }
30+
31+
/// <summary>
32+
/// Retrieves the requested feature from the collection.
33+
/// </summary>
34+
/// <typeparam name="TFeature">The feature key.</typeparam>
35+
/// <returns>The requested feature, or null if it is not present.</returns>
36+
TFeature Get<TFeature>();
37+
38+
/// <summary>
39+
/// Sets the given feature in the collection.
40+
/// </summary>
41+
/// <typeparam name="TFeature">The feature key.</typeparam>
42+
/// <param name="instance">The feature value.</param>
43+
void Set<TFeature>(TFeature instance);
3044
}
3145
}

src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,16 @@ public void Set(Type key, object value)
358358
throw new NotSupportedException();
359359
}
360360

361+
public TFeature Get<TFeature>()
362+
{
363+
return (TFeature)this[typeof(TFeature)];
364+
}
365+
366+
public void Set<TFeature>(TFeature instance)
367+
{
368+
this[typeof(TFeature)] = instance;
369+
}
370+
361371
IEnumerator IEnumerable.GetEnumerator()
362372
{
363373
return GetEnumerator();

0 commit comments

Comments
 (0)