summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Web/Framework/CommaDelimitedModelBinderProvider.cs
diff options
context:
space:
mode:
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;
+ }
+ }
+}