DotNetNext / SqlSugar

.Net aot ORM Fastest ORM Simple Easy VB.NET Sqlite orm Oracle ORM Mysql Orm 虚谷数据库 postgresql ORm SqlServer oRm 达梦 ORM 人大金仓 ORM 神通ORM C# ORM , C# ORM .NET ORM NET5 ORM .NET6 ORM ClickHouse orm QuestDb ,TDengine ORM,OceanBase orm,GaussDB orm ,Tidb orm Object/Relational Mapping
https://www.donet5.com/Home/Doc
MIT License
5.24k stars 1.33k forks source link

Update ValidateExtensions.cs #1127

Closed xuejmnet closed 1 year ago

xuejmnet commented 1 year ago

性能优化判断集合是否有元素应该使用Any,count会迭代所有次数,any只迭代一次

DotNetNext commented 1 year ago

//正确逻辑 if (thisValue == null || thisValue.Count() == 0) return true;

//错误逻辑 if (thisValue == null || thisValue.Any()) return true;

MonkSoul commented 1 year ago

image

DotNetNext commented 1 year ago

应该是 !thisValue.Any())

xuejmnet commented 1 year ago

@DotNetNext @MonkSoul 是的,web编辑忘了不好意思

xuejmnet commented 1 year ago

@DotNetNext

public static bool IsCollectionsList(this string thisValue)
        {
            return (thisValue + "").StartsWith("System.Collections.Generic.List")|| (thisValue + "").StartsWith("System.Collections.Generic.IEnumerable");
        }
        public static bool IsStringArray(this string thisValue)
        {
            return (thisValue + "").IsMatch(@"System\.[a-z,A-Z,0-9]+?\[\]");
        }
        public static bool IsEnumerable(this string thisValue)
        {
            return (thisValue + "").StartsWith("System.Linq.Enumerable");
        }

还有这三个我就不提交pr了,你们自己改一下吧,判断value==null直接返回false,不然性能还是低,而且是扩展方法应该会有很多处调用

DotNetNext commented 1 year ago

OK,后续手动合并