浏览代码

继续精简

懒得勤快 3 年之前
父节点
当前提交
302b5bc370

+ 1 - 1
Masuit.Tools.AspNetCore/Masuit.Tools.AspNetCore.csproj

@@ -18,7 +18,7 @@
         <LangVersion>latest</LangVersion>
         <RepositoryType>Github</RepositoryType>
         <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
-        <Version>1.0.1</Version>
+        <Version>1.0.2</Version>
         <FileVersion>1.0</FileVersion>
         <Company>masuit.com</Company>
         <AssemblyVersion>1.0</AssemblyVersion>

+ 0 - 17
Masuit.Tools.AspNetCore/ModelBinder/BodyOrDefaultBindingSource.cs

@@ -1,17 +0,0 @@
-using Microsoft.AspNetCore.Mvc.ModelBinding;
-
-namespace Masuit.Tools.AspNetCore.ModelBinder;
-
-public class BodyOrDefaultBindingSource : BindingSource
-{
-    public static readonly BindingSource BodyOrDefault = new BodyOrDefaultBindingSource("BodyOrDefault", "BodyOrDefault", true, true);
-
-    public BodyOrDefaultBindingSource(string id, string displayName, bool isGreedy, bool isFromRequest) : base(id, displayName, isGreedy, isFromRequest)
-    {
-    }
-
-    public override bool CanAcceptDataFrom(BindingSource bindingSource)
-    {
-        return bindingSource == Body || bindingSource == this;
-    }
-}

+ 8 - 1
Masuit.Tools.AspNetCore/ModelBinder/BodyOrDefaultModelBinder.cs

@@ -38,7 +38,14 @@ public class BodyOrDefaultModelBinder : IModelBinder
             }
             else if (request.ContentType.StartsWith("application/json"))
             {
-                value = JObject.Parse(text)[parameter] + "";
+                try
+                {
+                    value = JObject.Parse(text)[parameter] + "";
+                }
+                catch
+                {
+                    value = text;
+                }
             }
             else if (request.HasFormContentType)
             {

+ 1 - 1
Masuit.Tools.AspNetCore/ModelBinder/BodyOrDefaultModelBinderProvider.cs

@@ -26,7 +26,7 @@ public class BodyOrDefaultModelBinderProvider : IModelBinderProvider
 
     public IModelBinder GetBinder(ModelBinderProviderContext context)
     {
-        if (context.BindingInfo.BindingSource != null && context.BindingInfo.BindingSource.CanAcceptDataFrom(BodyOrDefaultBindingSource.BodyOrDefault))
+        if (context.BindingInfo.BindingSource != null && context.BindingInfo.BindingSource.CanAcceptDataFrom(BindingSource.Body))
         {
             var bodyBinder = _bodyModelBinderProvider.GetBinder(context);
             var complexBinder = _complexDataModelBinderProvider.GetBinder(context);

+ 0 - 10
Masuit.Tools.AspNetCore/ModelBinder/FromBodyOrDefaultAttribute.cs

@@ -1,10 +0,0 @@
-using System;
-using Microsoft.AspNetCore.Mvc.ModelBinding;
-
-namespace Masuit.Tools.AspNetCore.ModelBinder;
-
-[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
-public class FromBodyOrDefaultAttribute : Attribute, IBindingSourceMetadata
-{
-    public BindingSource BindingSource => BodyOrDefaultBindingSource.BodyOrDefault;
-}

+ 1 - 1
Masuit.Tools.sln

@@ -27,7 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masuit.Tools.Excel", "Masui
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masuit.Tools.Net45", "Masuit.Tools.Net45\Masuit.Tools.Net45.csproj", "{F51077A5-1CCA-4576-89BB-5447AC3D8DBC}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masuit.Tools.AspNetCore", "Masuit.Tools.AspNetCore\Masuit.Tools.AspNetCore.csproj", "{73BA93B7-C6AE-4B39-892E-3596D91BF96C}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masuit.Tools.AspNetCore", "Masuit.Tools.AspNetCore\Masuit.Tools.AspNetCore.csproj", "{73BA93B7-C6AE-4B39-892E-3596D91BF96C}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution