From 1529356162b19f80b20ea2b01d7f8e2580183c9c Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Thu, 18 Apr 2024 11:33:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/GenericTypeExtensions.cs | 32 +++++------ .../Helper/DynamicLinqFactory.cs | 6 +- .../Helper/GenericTypeExtensions.cs | 56 ------------------- .../GenericTypeExtensions.cs | 30 ---------- 4 files changed, 18 insertions(+), 106 deletions(-) delete mode 100644 Tiobon.Core.Common/Helper/GenericTypeExtensions.cs delete mode 100644 Tiobon.Core.Extensions/ServiceExtensions/GenericTypeExtensions.cs diff --git a/Tiobon.Core.Common/Extensions/GenericTypeExtensions.cs b/Tiobon.Core.Common/Extensions/GenericTypeExtensions.cs index 99c26abc..a5304fad 100644 --- a/Tiobon.Core.Common/Extensions/GenericTypeExtensions.cs +++ b/Tiobon.Core.Common/Extensions/GenericTypeExtensions.cs @@ -34,25 +34,25 @@ namespace Tiobon.Core.Common.Extensions /// 类型 /// 泛型类型 /// bool - // public static bool HasImplementedRawGeneric(this Type type, Type generic) - // { - // // 检查接口类型 - // var isTheRawGenericType = type.GetInterfaces().Any(IsTheRawGenericType); - // if (isTheRawGenericType) return true; + public static bool HasImplementedRawGeneric(this Type type, Type generic) + { + // 检查接口类型 + var isTheRawGenericType = type.GetInterfaces().Any(IsTheRawGenericType); + if (isTheRawGenericType) return true; - // // 检查类型 - // while (type != null && type != typeof(object)) - // { - // isTheRawGenericType = IsTheRawGenericType(type); - // if (isTheRawGenericType) return true; - // type = type.BaseType; - // } + // 检查类型 + while (type != null && type != typeof(object)) + { + isTheRawGenericType = IsTheRawGenericType(type); + if (isTheRawGenericType) return true; + type = type.BaseType; + } - // return false; + return false; - // // 判断逻辑 - // bool IsTheRawGenericType(Type type) => generic == (type.IsGenericType ? type.GetGenericTypeDefinition() : type); - // } + // 判断逻辑 + bool IsTheRawGenericType(Type t) => generic == (t.IsGenericType ? t.GetGenericTypeDefinition() : t); + } /// /// 复制 的副本 diff --git a/Tiobon.Core.Common/Helper/DynamicLinqFactory.cs b/Tiobon.Core.Common/Helper/DynamicLinqFactory.cs index f2e6017f..c383497c 100644 --- a/Tiobon.Core.Common/Helper/DynamicLinqFactory.cs +++ b/Tiobon.Core.Common/Helper/DynamicLinqFactory.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; +using System.ComponentModel.DataAnnotations; using System.Linq.Expressions; using System.Reflection; using System.Text; using System.Text.RegularExpressions; using Mapster; +using Tiobon.Core.Common.Extensions; namespace Tiobon.Core.Common.Helper { diff --git a/Tiobon.Core.Common/Helper/GenericTypeExtensions.cs b/Tiobon.Core.Common/Helper/GenericTypeExtensions.cs deleted file mode 100644 index 3d2192f7..00000000 --- a/Tiobon.Core.Common/Helper/GenericTypeExtensions.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Linq; - -namespace Tiobon.Core.Common.Helper -{ - public static class GenericTypeExtensions - { - /// - /// 判断类型是否实现某个泛型 - /// - /// 类型 - /// 泛型类型 - /// bool - public static bool HasImplementedRawGeneric(this Type type, Type generic) - { - // 检查接口类型 - var isTheRawGenericType = type.GetInterfaces().Any(IsTheRawGenericType); - if (isTheRawGenericType) return true; - - // 检查类型 - while (type != null && type != typeof(object)) - { - isTheRawGenericType = IsTheRawGenericType(type); - if (isTheRawGenericType) return true; - type = type.BaseType; - } - - return false; - - // 判断逻辑 - bool IsTheRawGenericType(Type t) => generic == (t.IsGenericType ? t.GetGenericTypeDefinition() : t); - } - - public static string GetGenericTypeName(this Type type) - { - var typeName = string.Empty; - - if (type.IsGenericType) - { - var genericTypes = string.Join(",", type.GetGenericArguments().Select(t => t.Name).ToArray()); - typeName = $"{type.Name.Remove(type.Name.IndexOf('`'))}<{genericTypes}>"; - } - else - { - typeName = type.Name; - } - - return typeName; - } - - public static string GetGenericTypeName(this object @object) - { - return @object.GetType().GetGenericTypeName(); - } - } -} \ No newline at end of file diff --git a/Tiobon.Core.Extensions/ServiceExtensions/GenericTypeExtensions.cs b/Tiobon.Core.Extensions/ServiceExtensions/GenericTypeExtensions.cs deleted file mode 100644 index a0cd507e..00000000 --- a/Tiobon.Core.Extensions/ServiceExtensions/GenericTypeExtensions.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Linq; - -namespace Tiobon.Core.Extensions -{ - public static class GenericTypeExtensions - { - public static string GetGenericTypeName(this Type type) - { - var typeName = string.Empty; - - if (type.IsGenericType) - { - var genericTypes = string.Join(",", type.GetGenericArguments().Select(t => t.Name).ToArray()); - typeName = $"{type.Name.Remove(type.Name.IndexOf('`'))}<{genericTypes}>"; - } - else - { - typeName = type.Name; - } - - return typeName; - } - - public static string GetGenericTypeName(this object @object) - { - return @object.GetType().GetGenericTypeName(); - } - } -}