Move generic Get/Set into Interface
This commit is contained in:
parent
364a712cb3
commit
62ec29b6af
|
|
@ -93,6 +93,16 @@ namespace Microsoft.AspNet.Http.Features
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TFeature Get<TFeature>()
|
||||||
|
{
|
||||||
|
return (TFeature)this[typeof(TFeature)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set<TFeature>(TFeature instance)
|
||||||
|
{
|
||||||
|
this[typeof(TFeature)] = instance;
|
||||||
|
}
|
||||||
|
|
||||||
private class KeyComparer : IEqualityComparer<KeyValuePair<Type, object>>
|
private class KeyComparer : IEqualityComparer<KeyValuePair<Type, object>>
|
||||||
{
|
{
|
||||||
public bool Equals(KeyValuePair<Type, object> x, KeyValuePair<Type, object> y)
|
public bool Equals(KeyValuePair<Type, object> x, KeyValuePair<Type, object> y)
|
||||||
|
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
// 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.AspNet.Http.Features
|
|
||||||
{
|
|
||||||
public static class FeatureCollectionExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves the requested feature from the collection.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TFeature">The feature key.</typeparam>
|
|
||||||
/// <param name="features">The collection.</param>
|
|
||||||
/// <returns>The requested feature, or null if it is not present.</returns>
|
|
||||||
public static TFeature Get<TFeature>(this IFeatureCollection features)
|
|
||||||
{
|
|
||||||
return (TFeature)features[typeof(TFeature)];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the given feature in the collection.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TFeature">The feature key.</typeparam>
|
|
||||||
/// <param name="features">The collection.</param>
|
|
||||||
/// <param name="instance">The feature value.</param>
|
|
||||||
public static void Set<TFeature>(this IFeatureCollection features, TFeature instance)
|
|
||||||
{
|
|
||||||
features[typeof(TFeature)] = instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -27,5 +27,19 @@ namespace Microsoft.AspNet.Http.Features
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <returns>The requested feature, or null if it is not present.</returns>
|
/// <returns>The requested feature, or null if it is not present.</returns>
|
||||||
object this[Type key] { get; set; }
|
object this[Type key] { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the requested feature from the collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TFeature">The feature key.</typeparam>
|
||||||
|
/// <returns>The requested feature, or null if it is not present.</returns>
|
||||||
|
TFeature Get<TFeature>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the given feature in the collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TFeature">The feature key.</typeparam>
|
||||||
|
/// <param name="instance">The feature value.</param>
|
||||||
|
void Set<TFeature>(TFeature instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -358,6 +358,16 @@ namespace Microsoft.AspNet.Owin
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TFeature Get<TFeature>()
|
||||||
|
{
|
||||||
|
return (TFeature)this[typeof(TFeature)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set<TFeature>(TFeature instance)
|
||||||
|
{
|
||||||
|
this[typeof(TFeature)] = instance;
|
||||||
|
}
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
{
|
{
|
||||||
return GetEnumerator();
|
return GetEnumerator();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue