diff --git a/src/Umbraco.Web/FormDataCollectionExtensions.cs b/src/Umbraco.Web/FormDataCollectionExtensions.cs deleted file mode 100644 index 3f2840c8ca..0000000000 --- a/src/Umbraco.Web/FormDataCollectionExtensions.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http.Formatting; -using System.Text; -using Umbraco.Core; - -namespace Umbraco.Web -{ - // Migrated to .NET Core (as FormCollectionExtensions) - public static class FormDataCollectionExtensions - { - /// - /// Converts a dictionary object to a query string representation such as: - /// firstname=shannon&lastname=deminick - /// - /// - /// Any keys found in this collection will be removed from the output - /// - public static string ToQueryString(this FormDataCollection items, params string[] keysToIgnore) - { - if (items == null) return ""; - if (items.Any() == false) return ""; - - var builder = new StringBuilder(); - foreach (var i in items.Where(i => keysToIgnore.InvariantContains(i.Key) == false)) - { - builder.Append(string.Format("{0}={1}&", i.Key, i.Value)); - } - return builder.ToString().TrimEnd('&'); - } - - /// - /// Converts the FormCollection to a dictionary - /// - /// - /// - public static IDictionary ToDictionary(this FormDataCollection items) - { - return items.ToDictionary(x => x.Key, x => (object)x.Value); - } - - /// - /// Returns the value of a mandatory item in the FormCollection - /// - /// - /// - /// - public static string GetRequiredString(this FormDataCollection items, string key) - { - if (items.HasKey(key) == false) - throw new ArgumentNullException("The " + key + " query string parameter was not found but is required"); - return items.Single(x => x.Key.InvariantEquals(key)).Value; - } - - /// - /// Checks if the collection contains the key - /// - /// - /// - /// - public static bool HasKey(this FormDataCollection items, string key) - { - return items.Any(x => x.Key.InvariantEquals(key)); - } - - /// - /// Returns the object based in the collection based on it's key. This does this with a conversion so if it doesn't convert a null object is returned. - /// - /// - /// - /// - /// - public static T GetValue(this FormDataCollection items, string key) - { - var val = items.Get(key); - if (string.IsNullOrEmpty(val)) return default(T); - - var converted = val.TryConvertTo(); - return converted.Success - ? converted.Result - : default(T); - } - - /// - /// Returns the object based in the collection based on it's key. This does this with a conversion so if it doesn't convert or the query string is no there an exception is thrown - /// - /// - /// - /// - /// - public static T GetRequiredValue(this FormDataCollection items, string key) - { - var val = items.Get(key); - if (string.IsNullOrEmpty(val)) - throw new InvalidOperationException($"The required query string parameter {key} is missing"); - - var converted = val.TryConvertTo(); - return converted.Success - ? converted.Result - : throw new InvalidOperationException($"The required query string parameter {key} cannot be converted to type {typeof(T)}"); - } - } -} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index a0d0e65e21..27a90b5d7e 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -284,7 +284,6 @@ -