zijian666.AnyExtensions 1.0.15.4

dotnet add package zijian666.AnyExtensions --version 1.0.15.4
NuGet\Install-Package zijian666.AnyExtensions -Version 1.0.15.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="zijian666.AnyExtensions" Version="1.0.15.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add zijian666.AnyExtensions --version 1.0.15.4
#r "nuget: zijian666.AnyExtensions, 1.0.15.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install zijian666.AnyExtensions as a Cake Addin
#addin nuget:?package=zijian666.AnyExtensions&version=1.0.15.4

// Install zijian666.AnyExtensions as a Cake Tool
#tool nuget:?package=zijian666.AnyExtensions&version=1.0.15.4

any-extensions

万物皆可扩展

zijian666.AnyExtensions 更新说明
zijian666.AnyExtensions.ComponentModel 更新说明

NuGet

zijian666.AnyExtensions
zijian666.AnyExtensions.ComponentModel

扩展方法

布尔型扩展

BooleanExtensions

序号 扩展方法 说明 版本
1 Not 取反 1.0.0
2 IsNullOrTrue 值为 null 或 true 1.0.0
3 IsNullOrFalse 值为 null 或 false 1.0.0
4 IsTrue 有值 且为 true 1.0.0
5 IsFalse 有值 且为 false 1.0.0

集合扩展

CollectionExtensions

序号 扩展方法 说明 版本
1 DistinctWithoutNull 返回排除空对象(null)后的去重集合 1.0.0
2 GetValueOrDefault 获取字典中的值如果key不存在则返回默认值 1.0.0
3 GetValues 从字典中批量获取对象 1.0.0
4 IsSame 比较2个数组是否一致 1.0.0
5 IsNullOrEmpty 判断一个集合是否为空 1.0.0
6 Join 调用 string.Join 生成新的字符串 1.0.0
7 ToHashSet 创建 HashSet 1.0.0
8 WithoutNull 排除集合中的空对象(null 1.0.0
9 WithoutWhiteSpace 排除集合中的空白字符串 1.0.0
10 WithoutDefaultValue 排除集合中的默认值 1.0.0
11 AsReadOnly 转为只读集合 1.0.0
12 Each 循环集合 1.0.0
13 FindByIn 筛选集合中某个属性值包含在另一集合中的数据 1.0.0
14 FindByNotIn 筛选集合中某个属性值不包含在另一集合中的数据 1.0.6
15 WhereIf 判断后调用筛选函数 1.0.2
16 If 判断后执行其他操作 1.0.12
17 AsHashSet 转为 HashSet,如果本身就是HashSet则直接返回 1.0.15

区域信息扩展

CultureInfoExtensions

序号 扩展方法 说明 版本
1 GetStringComparer 使用CompareOptions获取字符串比较器 1.0.13
2 CreateDictionary 使用CompareOptions创建字典 1.0.13
3 CreateHashSet 使用CompareOptions创建哈希集合 1.0.13

时间扩展

DateTimeExtensions

也适用于DateTimeOffset

序号 扩展方法 说明 版本
1 ToDateTimeString 将时间类型转为日期时间字符串 yyyy-MM-dd HH:mm:ss 1.0.0
2 ToDateString 将时间类型转为日期字符串 yyyy-MM-dd 1.0.0
3 ToTimeString 将时间类型转为时间字符串 HH:mm:ss 1.0.0
4 LastSecondsOfDay 获取此实例时间所在的那一天的最后一秒 1.0.0
5 FirstDayOfMonth 获取此实例时间所在的那个月的第一天 1.0.0
6 LastDayOfMonth 获取此实例时间所在的那个月的最后一天 1.0.0
7 FirstDayOfYear 获取此实例时间所在的那一年的第一天 1.0.0
8 LastDayOfYear 获取此实例时间所在的那一年的最后一天 1.0.0
9 SundayOfWeek 获取此实例时间所在的那一周的星期日 1.0.0
9 MondayOfWeek 获取此实例时间所在的那一周的星期一 1.0.0
9 TuesdayOfWeek 获取此实例时间所在的那一周的星期二 1.0.0
9 WednesdayOfWeek 获取此实例时间所在的那一周的星期三 1.0.0
9 ThursdayOfWeek 获取此实例时间所在的那一周的星期四 1.0.0
9 FridayOfWeek 获取此实例时间所在的那一周的星期五 1.0.0
9 SaturdayOfWeek 获取此实例时间所在的那一周的星期六 1.0.0

枚举扩展

EnumExtensions

序号 扩展方法 说明 版本
1 GetDescription 获取枚举值的描述 1.0.0
2 FlagsSplit 拆分 FlagsAttribute 标记的枚举 1.0.0
3 FlagsCombine 合并枚举 1.0.0
4 GetFieldInfo 获取枚举对应的字段FieldInfo 1.0.0

异常操作扩展

ExceptionExtensions

序号 扩展方法 说明 版本
1 Check 开启参数校验 1.0.0
2 ThrowIfNull 判断参数是否为null 1.0.0
3 ThrowIfDefault 判断参数是否为默认值 1.0.0
4 ThrowIfEmpty 判断参数(集合或字符串)是否为空 1.0.0
5 GetAllExceptions 循环当前异常的所有内部异常 1.0.0
6 ThrowFirstError 抛出第一个异常,如果没有则不执行任何操作 1.0.0
7 ThrowAllError 如果存在一个以上的异常,则尝试聚合异常后抛出; 如果只有一个异常直接抛出 1.0.0
8 Throw 如果异常不为空,则抛出异常 1.0.0
9 Aggregate 如果有必要,聚合异常,默认最大聚合异常10个,超过则丢弃 1.0.0

Linq表达式编译程序

ExpressionExtensions

序号 扩展方法 说明 版本
1 Property 访问属性,支持子属性,例如(propertyName = "Child.Name") 1.0.0
2 BodyProxy 使用新的参数代理表达树中的方法体 1.0.0
3 Proxy 使用新的参数构建表达式 1.0.0
4 FindParameter 尝试查找表达式中所使用的参数 1.0.0
5 Type 尝试获取表达式在操作中的类型 1.0.0
6 Call 构建调用静态方法的表达式 1.0.0
7 Lambda 构建泛型委托表达式 1.0.0
8 GreaterThan 构建比较表达式 1.0.0
9 GreaterThanOrEqual 构建比较表达式 1.0.0
10 LessThanOrEqual 构建比较表达式 1.0.0
11 Between 构建比较表达式 1.0.0
12 NotBetween 构建比较表达式 1.0.0
13 Equal 构建比较表达式 1.0.0
14 StringOperation 构建字符串操作的比较表达式 1.0.0
15 Like 构建字符串模糊匹配操作表达式 1.0.0
16 NotLike 构建字符串模糊匹配操作表达式 1.0.0
17 StartsWith 构建字符串操作的比较表达式 1.0.0
18 NotStartsWith 构建字符串操作的比较表达式 1.0.0
19 EndsWith 构建字符串操作的比较表达式 1.0.0
20 NotEndsWith 构建字符串操作的比较表达式 1.0.0

比较操作扩展

IComparableExtensions

序号 扩展方法 说明 版本
1 MinOf 返回不大于指定值的值 已废弃
2 MaxOf 返回不小于指定值的值 已废弃
3 BetweenOf 返回位于最大值和最小值之间的值 1.0.5
4 GreaterThan 返回不大于指定值的值 1.0.14
5 LessThan 返回不小于指定值的值 1.0.14

数字扩展

NumberExtensions

序号 扩展方法 说明 版本
1 Round 将小数值舍入到指定精度,默认四舍五入 1.0.0
2 Ceiling 返回大于或等于指定小数位的数 1.0.0
3 Floor 返回小于或等于指定小数位的数 1.0.0
4 Scale 按指定模式和位数对数字进行处理 1.0.0
5 ToDecimal 将double或float转为Decimal类型,15位有效数字内不会丢失精度 1.0.0

Object扩展

ObjectExtensions

序号 扩展方法 说明 版本
1 If 判断条件后确定是否执行操作 1.0.14

分页相关扩展方法

PagingExtensions

序号 扩展方法 说明 版本
1 Paging Linq分页 1.0.0

待查询对象扩展

QueryableExtensions

序号 扩展方法 说明 版本
1 LinqBuidler 创建表达式树构建程序 1.0.0
2 IsNullOrEmpty 确定序列中没有任何元素满足条件。参考集合扩展 1.0.0
3 ToHashSet 创建 HashSet。参考集合扩展 1.0.0
3 FindByIn 构建 where {columnName} in ( {values} ) 语句查询数据库 1.0.0
4 FindByNotIn 构建 where {columnName} not in ( {values} ) 语句查询数据库 1.0.6
5 FindByIds 构建 where Id in ( {values} ) 语句查询数据库 1.0.0
6 WithoutDeleted 排除已删除的数据,构建 where {IsDelete} != 1 语句查询数据库 1.0.0
7 Between 构建 where {columnName} >= {begin} and {columnName} <= {end} 语句查询数据库 1.0.0
8 OrderBy 使用字符串方式操作集合排序 1.0.0
9 ThenBy 使用字符串方式操作集合排序 1.0.0
10 WhereIf 判断后调用Where 1.0.0
11 If 判断后执行其他操作 1.0.12

字符串扩展

StringExtensions

序号 扩展方法 说明 版本
1 IsNullOrEmpty 指示字符串是 null 还是空字符串 ("")。 1.0.0
2 IsNullOrWhiteSpace 指示字符串是 null、空还是仅由空白字符组成。 1.0.0
3 EmptyOrDefault 如果字符串是 null 或空字符串 (""),则返回 defaultValue 1.0.0
4 WhiteSpaceOrDefault 如果字符串是null、空或是仅由空白字符组成,则返回 defaultValue 1.0.0
5 Split 按照指定符号切分字符串,并转为指定格式,如果不传默认分割为 ',', ' ', ';', '\n', '\r', '\t' 1.0.0
6 EncodeSqlLike 编码为 like 查询时可用的字符串 1.0.0
7 EncodeFileName 编码为 文件名可用的字符串(主要是将半角改为全角) 1.0.0
8 Slice 截断字符串(支持负索引,为从右往左的位置) 1.0.12
9 Masking 字符串脱敏 1.0.12
10 EqualsIgnoreCase 字符串比较忽略大小写 1.0.13
11 EqualsSqlServerString 字符串比较忽略大小写和全半角 1.0.13
12 Parse/TryParse 将字符串转换为它的等效指定类型 1.0.15

结构体扩展

StructExtensions

序号 扩展方法 说明 版本
1 IsNullOrDefault 判断值为空或默认值 1.0.0
2 NotNullOrDefault 判断值不是空或默认值 1.0.0

Task 扩展

TaskExtensions

序号 扩展方法 说明 版本
1 Then task 执行成功后执行下一个操作 1.0.15
2 Catch task 执行异常时执行回调 1.0.15
3 Finally task 执行完成后,无论是否异常,都执行回调 1.0.15

System.ComponentModel 扩展包

ValidationExceptionExtensions

序号 扩展方法 说明 版本
1 ValidatEntity 实体类校验 1.0.0
序号 验证特性 说明 版本
1 ValidateAttribute 属性需要递归验证 1.0.6
2 NotAttribute 不允许指定的值 1.0.6
3 NotDefaultAttribute 不允许默认值 1.0.6
4 AllowAttribute 仅允许指定的值 1.0.7
5 EnumAttribute 取值范围必须是枚举已定义的值 1.0.7
6 NoScriptAttribute 字符串不能包含脚本 1.0.7

用于动态构建单一参数的表达式树

LinqExpressionBuilder 基于ExpressionExtensions实现

序号 扩展方法 说明 版本
1 Equal 构建比较表达式 1.0.0
2 GreaterThan 构建比较表达式 1.0.0
3 GreaterThanOrEqual 构建比较表达式 1.0.0
3 LessThanOrEqual 构建比较表达式 1.0.0
4 Between 构建比较表达式 1.0.0
5 NotBetween 构建比较表达式 1.0.0
6 StringOperation 构建字符串操作的比较表达式 1.0.0
7 Like 构建字符串模糊匹配操作表达式 1.0.0
9 NotLike 构建字符串模糊匹配操作表达式 1.0.0
10 StartsWith 构建字符串操作的比较表达式 1.0.0
11 NotStartsWith 构建字符串操作的比较表达式 1.0.0
12 EndsWith 构建字符串操作的比较表达式 1.0.0
13 NotEndsWith 构建字符串操作的比较表达式 1.0.0
13 And 使用And方式组合2个表达式 1.0.0
14 Or 使用Or方式组合2个表达式 1.0.0
15 Not 反转表达式的结果 1.0.0
16 Property 构建获取实体属性的表达式 1.0.0

<details> <summary>示例代码,点击展开</summary>

例1:

var query = db.AsQueryable();
var builder = query.LinqBuidler();

//     构建 list.Where(x => x.Number == number)ToList();
_ = query.Where(builder.Equal("Number", number)).ToList(); 


//     构建 list.Where(x => new []{1,2,3,4}.Contains(x.Number) )ToList();
_ = query.Where(builder.Equal("Number", new []{1,2,3,4})).ToList(); 

例2:

var where = builder.NotEqual("IsDelete", true); // 类型会做一些简单规则的转换,比如数据库是int 比较的值是bool

if ( ... )
{
    where = builder.And(where, builder.StartsWith("Code", "ORDER_0001"));
}

if ( ... )
{
    var begin = DateTime.Today;
    var end = DateTime.Today.LastSecondsOfDay();
    // Between 会正确处理 begin = null 或 end = null的情况, 但2个同时为null 会返回 x => false
    where = builder.And(where, builder.Between("CreateTime", begin, end));
}

if ( ... )
{
    where = builder.Not(where);
}

_ = query.Where(where).ToList();

</details>

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on zijian666.AnyExtensions:

Package Downloads
zijian666.AnyExtensions.ComponentModel

万物皆可扩展

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.15.4 69 4/12/2024
1.0.15.1 72 2/1/2024
1.0.15 79 2/1/2024
1.0.14.1 198 9/22/2023
1.0.14 174 9/14/2023
1.0.13 112 9/13/2023
1.0.12 116 9/12/2023
1.0.11 190 7/19/2023
1.0.10 386 2/2/2023
1.0.9 372 1/10/2023
1.0.7 295 1/5/2023
1.0.6 520 12/15/2022
1.0.5 307 12/14/2022
1.0.4 427 12/8/2022
1.0.3 649 11/24/2022
1.0.2 372 11/17/2022
1.0.1 509 11/6/2022