summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Web/Framework/CommaDelimitedModelBinderProvider.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-22 01:57:18 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-22 01:57:18 -0400
commit86e55596786f8d65854a75632512750b6e09faae (patch)
tree27f082b50b70f3d3b020855f9ac8b3b1cc5430f6 /src/StardewModdingAPI.Web/Framework/CommaDelimitedModelBinderProvider.cs
parentef60b8d32abf7c8613749766155d80139e33b9d1 (diff)
downloadSMAPI-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.cs27
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;
+ }
+ }
+}