From 62ec29b6af32e229c64f2f1410215109d8d2b8a0 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 31 Dec 2015 20:18:24 +0000 Subject: [PATCH] Move generic Get/Set into Interface --- .../FeatureCollection.cs | 10 +++++++ .../FeatureCollectionExtensions.cs | 30 ------------------- .../IFeatureCollection.cs | 14 +++++++++ .../OwinFeatureCollection.cs | 10 +++++++ 4 files changed, 34 insertions(+), 30 deletions(-) delete mode 100644 src/Microsoft.AspNet.Http.Features/FeatureCollectionExtensions.cs diff --git a/src/Microsoft.AspNet.Http.Features/FeatureCollection.cs b/src/Microsoft.AspNet.Http.Features/FeatureCollection.cs index 246af4d183..79e6916752 100644 --- a/src/Microsoft.AspNet.Http.Features/FeatureCollection.cs +++ b/src/Microsoft.AspNet.Http.Features/FeatureCollection.cs @@ -93,6 +93,16 @@ namespace Microsoft.AspNet.Http.Features } } + public TFeature Get() + { + return (TFeature)this[typeof(TFeature)]; + } + + public void Set(TFeature instance) + { + this[typeof(TFeature)] = instance; + } + private class KeyComparer : IEqualityComparer> { public bool Equals(KeyValuePair x, KeyValuePair y) diff --git a/src/Microsoft.AspNet.Http.Features/FeatureCollectionExtensions.cs b/src/Microsoft.AspNet.Http.Features/FeatureCollectionExtensions.cs deleted file mode 100644 index 86681fde3f..0000000000 --- a/src/Microsoft.AspNet.Http.Features/FeatureCollectionExtensions.cs +++ /dev/null @@ -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 - { - /// - /// Retrieves the requested feature from the collection. - /// - /// The feature key. - /// The collection. - /// The requested feature, or null if it is not present. - public static TFeature Get(this IFeatureCollection features) - { - return (TFeature)features[typeof(TFeature)]; - } - - /// - /// Sets the given feature in the collection. - /// - /// The feature key. - /// The collection. - /// The feature value. - public static void Set(this IFeatureCollection features, TFeature instance) - { - features[typeof(TFeature)] = instance; - } - } -} diff --git a/src/Microsoft.AspNet.Http.Features/IFeatureCollection.cs b/src/Microsoft.AspNet.Http.Features/IFeatureCollection.cs index c7ad165c66..454cafa3dc 100644 --- a/src/Microsoft.AspNet.Http.Features/IFeatureCollection.cs +++ b/src/Microsoft.AspNet.Http.Features/IFeatureCollection.cs @@ -27,5 +27,19 @@ namespace Microsoft.AspNet.Http.Features /// /// The requested feature, or null if it is not present. object this[Type key] { get; set; } + + /// + /// Retrieves the requested feature from the collection. + /// + /// The feature key. + /// The requested feature, or null if it is not present. + TFeature Get(); + + /// + /// Sets the given feature in the collection. + /// + /// The feature key. + /// The feature value. + void Set(TFeature instance); } } diff --git a/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs b/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs index acf3e2215c..1a1b5b183d 100644 --- a/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs +++ b/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs @@ -358,6 +358,16 @@ namespace Microsoft.AspNet.Owin throw new NotSupportedException(); } + public TFeature Get() + { + return (TFeature)this[typeof(TFeature)]; + } + + public void Set(TFeature instance) + { + this[typeof(TFeature)] = instance; + } + IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator();