diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-22 01:57:18 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-22 01:57:18 -0400 |
commit | 86e55596786f8d65854a75632512750b6e09faae (patch) | |
tree | 27f082b50b70f3d3b020855f9ac8b3b1cc5430f6 /src/StardewModdingAPI.Web/Framework/CommaDelimitedModelBinderProvider.cs | |
parent | ef60b8d32abf7c8613749766155d80139e33b9d1 (diff) | |
download | SMAPI-86e55596786f8d65854a75632512750b6e09faae.tar.gz SMAPI-86e55596786f8d65854a75632512750b6e09faae.tar.bz2 SMAPI-86e55596786f8d65854a75632512750b6e09faae.zip |
switch mod update endpoint to GET with comma-delimited mod keys (#336)
Diffstat (limited to 'src/StardewModdingAPI.Web/Framework/CommaDelimitedModelBinderProvider.cs')
-rw-r--r-- | src/StardewModdingAPI.Web/Framework/CommaDelimitedModelBinderProvider.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/StardewModdingAPI.Web/Framework/CommaDelimitedModelBinderProvider.cs b/src/StardewModdingAPI.Web/Framework/CommaDelimitedModelBinderProvider.cs new file mode 100644 index 00000000..1b3f0073 --- /dev/null +++ b/src/StardewModdingAPI.Web/Framework/CommaDelimitedModelBinderProvider.cs @@ -0,0 +1,27 @@ +using System; +using Microsoft.AspNetCore.Mvc.ModelBinding; + +namespace StardewModdingAPI.Web.Framework +{ + /// <summary>Provides comma-delimited model binds for mapping parameters.</summary> + /// <remarks>Derived from <a href="https://stackoverflow.com/a/43655986/262123" />.</remarks> + public class CommaDelimitedModelBinderProvider : IModelBinderProvider + { + /********* + ** Public methods + *********/ + /// <summary>Creates a model binder based on the given context.</summary> + /// <param name="context">The model binding context.</param> + public IModelBinder GetBinder(ModelBinderProviderContext context) + { + // validate + if (context == null) + throw new ArgumentNullException(nameof(context)); + + // get model binder + return context.Metadata.IsEnumerableType && !context.Metadata.ElementMetadata.IsComplexType + ? new CommaDelimitedModelBinder() + : null; + } + } +} |