懒得勤快 3 years ago
parent
commit
b539294944

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

@@ -4,7 +4,7 @@
     <LangVersion>latest</LangVersion>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <CodeAnalysisRuleSet />
-    <Version>2.4.8.9</Version>
+    <Version>2.4.8.10</Version>
     <Authors>懒得勤快</Authors>
     <Description>Masuit.Tools基础公共库,包含一些常用的操作类,大都是静态类,加密解密,反射操作,Excel简单导出,权重随机筛选算法,分布式短id,表达式树,linq扩展,文件压缩,多线程下载和FTP客户端,硬件信息,字符串扩展方法,日期时间扩展操作,中国农历,大文件拷贝,图像裁剪,验证码,断点续传,集合扩展等常用封装。</Description>
     <Copyright>懒得勤快,长空X</Copyright>

+ 1 - 1
Masuit.Tools.Abstractions/Models/TreeExtensions.cs

@@ -492,7 +492,7 @@ namespace Masuit.Tools.Models
         /// </summary>
         public static T Root<T>(this T tree) where T : ITreeParent<T> => GetRoot(tree, t => t.Parent);
 
-        private static string GetFullPath<T>(T c, Func<T, string> selector, string separator = "/") where T : ITreeParent<T> => c.Parent != null ? GetFullPath(c.Parent, selector) + separator + selector(c) : selector(c);
+        private static string GetFullPath<T>(T c, Func<T, string> selector, string separator = "/") where T : ITreeParent<T> => c.Parent != null ? GetFullPath(c.Parent, selector, separator) + separator + selector(c) : selector(c);
 
         /// <summary>
         /// 根节点

+ 6 - 9
Masuit.Tools.Abstractions/Systems/CompositeContractResolver.cs

@@ -13,17 +13,14 @@ public class CompositeContractResolver : FallbackJsonPropertyResolver
     protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
     {
         var property = base.CreateProperty(member, memberSerialization);
-        if (property is { Writable: true })
+        if (property.AttributeProvider.GetAttributes(typeof(DeserializeOnlyJsonPropertyAttribute), true).Union(property.AttributeProvider.GetAttributes(typeof(SerializeIgnoreAttribute), true)).Any())
         {
-            if (property.AttributeProvider.GetAttributes(typeof(DeserializeOnlyJsonPropertyAttribute), true).Union(property.AttributeProvider.GetAttributes(typeof(SerializeIgnoreAttribute), true)).Any())
-            {
-                property.ShouldSerialize = _ => false;
-            }
+            property.ShouldSerialize = _ => false;
+        }
 
-            if (property.AttributeProvider.GetAttributes(typeof(SerializeOnlyJsonPropertyAttribute), true).Union(property.AttributeProvider.GetAttributes(typeof(DeserializeIgnoreAttribute), true)).Any())
-            {
-                property.ShouldDeserialize = _ => false;
-            }
+        if (property.AttributeProvider.GetAttributes(typeof(SerializeOnlyJsonPropertyAttribute), true).Union(property.AttributeProvider.GetAttributes(typeof(DeserializeIgnoreAttribute), true)).Any())
+        {
+            property.ShouldDeserialize = _ => false;
         }
 
         return property;

+ 13 - 26
Masuit.Tools.Abstractions/Systems/FallbackJsonPropertyResolver.cs

@@ -70,28 +70,6 @@ public class FallbackJsonPropertyResolver : CamelCasePropertyNamesContractResolv
         return DeserializeIgnores[type].Contains(propertyName, StringComparer.CurrentCultureIgnoreCase);
     }
 
-    /// <summary>
-    /// The decision logic goes here
-    /// </summary>
-    /// <param name="member"></param>
-    /// <param name="memberSerialization"></param>
-    /// <returns></returns>
-    protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
-    {
-        var property = base.CreateProperty(member, memberSerialization);
-        if (IsSerializeIgnored(property.DeclaringType, property.PropertyName))
-        {
-            property.ShouldSerialize = _ => false;
-        }
-
-        if (IsDeserializeIgnored(property.DeclaringType, property.PropertyName))
-        {
-            property.ShouldDeserialize = _ => false;
-        }
-
-        return property;
-    }
-
     protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
     {
         var typeMembers = GetSerializableMembers(type).DistinctBy(m => m.Name);
@@ -100,23 +78,32 @@ public class FallbackJsonPropertyResolver : CamelCasePropertyNamesContractResolv
         foreach (var member in typeMembers)
         {
             var property = CreateProperty(member, memberSerialization);
-            properties.Add(property);
+            if (IsSerializeIgnored(property.DeclaringType, property.PropertyName))
+            {
+                property.ShouldSerialize = _ => false;
+            }
 
-            var fallbackAttribute = member.GetCustomAttribute<FallbackJsonProperty>();
+            if (IsDeserializeIgnored(property.DeclaringType, property.PropertyName))
+            {
+                property.ShouldDeserialize = _ => false;
+            }
 
+            properties.RemoveAll(p => p.PropertyName == property.PropertyName);
+            properties.Add(property);
+            var fallbackAttribute = member.GetCustomAttribute<FallbackJsonProperty>();
             if (fallbackAttribute == null)
             {
                 continue;
             }
 
             property.PropertyName = fallbackAttribute.PreferredName;
-
             foreach (var alternateName in fallbackAttribute.FallbackReadNames)
             {
                 properties.RemoveAll(p => p.PropertyName == alternateName);
                 var fallbackProperty = CreateProperty(member, memberSerialization);
                 fallbackProperty.PropertyName = alternateName;
-                fallbackProperty.ShouldSerialize = (x) => false;
+                fallbackProperty.ShouldSerialize = _ => false;
+                fallbackProperty.ShouldDeserialize = _ => true;
                 properties.Add(fallbackProperty);
             }
         }

+ 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.5.9</Version>
+        <Version>1.0.5.10</Version>
         <FileVersion>1.0</FileVersion>
         <Company>masuit.com</Company>
         <AssemblyVersion>1.0</AssemblyVersion>

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

@@ -18,7 +18,7 @@ github:https://github.com/ldqk/Masuit.Tools
         <UserSecretsId>830c282f-f7c1-42be-8651-4cd06ac8e73f</UserSecretsId>
         <RepositoryType>Github</RepositoryType>
         <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
-        <Version>2.4.8.9</Version>
+        <Version>2.4.8.10</Version>
         <FileVersion>2.4.5.6</FileVersion>
         <Company>masuit.com</Company>
         <AssemblyVersion>2.4.5.6</AssemblyVersion>

+ 1 - 1
Masuit.Tools.Net45/package.nuspec

@@ -4,7 +4,7 @@
     <!--*-->
     <id>Masuit.Tools.Net45</id>
     <!--*-->
-    <version>2.4.8.8</version>
+    <version>2.4.8.10</version>
     <title>Masuit.Tools</title>
     <!--*-->
     <authors>懒得勤快</authors>

+ 1 - 1
Masuit.Tools/package.nuspec

@@ -4,7 +4,7 @@
     <!--*-->
     <id>Masuit.Tools.Net</id>
     <!--*-->
-    <version>2.4.8.8</version>
+    <version>2.4.8.10</version>
     <title>Masuit.Tools</title>
     <!--*-->
     <authors>懒得勤快</authors>