![]() |
VOOZH | about |
dotnet add package TJC.Cyclops.Linq --version 2026.6.11.2
NuGet\Install-Package TJC.Cyclops.Linq -Version 2026.6.11.2
<PackageReference Include="TJC.Cyclops.Linq" Version="2026.6.11.2" />
<PackageVersion Include="TJC.Cyclops.Linq" Version="2026.6.11.2" />Directory.Packages.props
<PackageReference Include="TJC.Cyclops.Linq" />Project file
paket add TJC.Cyclops.Linq --version 2026.6.11.2
#r "nuget: TJC.Cyclops.Linq, 2026.6.11.2"
#:package TJC.Cyclops.Linq@2026.6.11.2
#addin nuget:?package=TJC.Cyclops.Linq&version=2026.6.11.2Install as a Cake Addin
#tool nuget:?package=TJC.Cyclops.Linq&version=2026.6.11.2Install as a Cake Tool
🔍 强大的LINQ扩展库 🔍
Cyclops.Linq 是企服版框架中的LINQ扩展库,提供了丰富的LINQ扩展方法和查询工具,用于增强.NET标准LINQ功能,简化复杂数据查询和转换操作。该项目旨在解决企业应用开发中常见的数据处理需求,提供更强大、更灵活、更易用的数据查询能力。Cyclops.Linq包含集合操作、查询优化、延迟执行增强、特殊数据结构支持等多个功能模块,为开发者提供了全面的LINQ增强工具集。
dotnet add package TJC.Cyclops.Linq
Cyclops.Linq作为扩展方法库,无需特殊配置,只需在使用时引入命名空间即可:
using Cyclops.Linq;
using Cyclops.Linq;
// 基本条件过滤
var activeUsers = users.WhereIf(isActive, u => u.IsActive);
// 多条件过滤
var filteredUsers = users
.WhereIf(filterByName, u => u.Name.Contains(searchName))
.WhereIf(filterByAge, u => u.Age >= minAge && u.Age <= maxAge)
.WhereIf(filterByRole, u => u.Role == selectedRole);
// 排除空值
var nonEmptyEmails = users.WhereNotNull(u => u.Email);
// 范围过滤
var youngUsers = users.WhereBetween(u => u.Age, 18, 30);
// 集合包含过滤
var vipUsers = users.WhereIn(u => u.UserId, vipIds);
var regularUsers = users.WhereNotIn(u => u.UserId, vipIds);
using Cyclops.Linq;
// 不区分大小写排序
var sortedUsers = users.OrderByCaseInsensitive(u => u.Name);
// 随机排序(用于随机展示或抽样)
var randomUsers = users.OrderByRandom();
// 自定义优先级排序
var prioritizedTasks = tasks.OrderByPriority(t => {
if (t.IsUrgent) return 0; // 最高优先级
if (t.IsImportant) return 1; // 中优先级
return 2; // 低优先级
});
// 复杂排序(先按优先级,再按截止日期)
var sortedTasks = tasks
.OrderBy(t => t.Priority)
.ThenByCaseInsensitive(t => t.Title)
.ThenBy(t => t.DueDate);
using Cyclops.Linq;
// 带索引的投影
var indexedUsers = users.SelectWithIndex((user, index) => new {
Index = index + 1,
UserName = user.Name,
DisplayName = $"{index + 1}. {user.Name}"
});
// 条件投影
var userDtos = users.SelectIf(includeDetails,
u => new DetailedUserDto { Id = u.Id, Name = u.Name, Details = u.Details },
u => new BasicUserDto { Id = u.Id, Name = u.Name }
);
// 异常处理投影
var safeValues = data.SelectWithExceptionHandling(
d => ConvertToTargetType(d),
defaultValue: defaultTargetValue
);
using Cyclops.Linq;
// 多级分组
var groupedByDepartmentAndRole = users.GroupByMulti(
u => u.Department,
u => u.Role
);
// 按日期范围分组(按月)
var ordersByMonth = orders.GroupByDateTime(o => o.OrderDate, DateGroupType.Month);
// 按数值范围分组
var usersByAgeGroup = users.GroupByRange(
u => u.Age,
ranges: new[] { 0, 18, 30, 50, 100 }
);
// 不区分大小写分组
var itemsByName = products.GroupByCaseInsensitive(p => p.Category);
using Cyclops.Linq;
// 构建层次结构
var departments = employees
.Select(e => new { Id = e.Id, Name = e.Name, ManagerId = e.ManagerId })
.AsHierarchy(e => e.Id, e => e.ManagerId)
.ToList();
// 扁平化层次结构
var allEmployees = departments.FlattenHierarchy().ToList();
// 深度优先遍历
var depthFirstEmployees = departments.TraverseDepthFirst(d => d.Children).ToList();
// 广度优先遍历
var breadthFirstEmployees = departments.TraverseBreadthFirst(d => d.Children).ToList();
// 查找所有下属
var subordinates = manager.TraverseDepthFirst(m => m.DirectReports).ToList();
// 获取层级信息
var employeesWithLevel = departments
.TraverseDepthFirst(d => d.Children)
.Select(e => new {
Name = e.Name,
Level = e.Level()
})
.ToList();
using Cyclops.Linq;
// 安全统计(处理空集合)
var avgAge = users.AverageOrDefault(u => u.Age, 0);
var totalSalary = users.SumOrDefault(u => u.Salary, 0);
// 高级统计
var medianSalary = employees.Median(e => e.Salary);
var modeDepartment = employees.Mode(e => e.Department);
var percentile90Salary = employees.Percentile(e => e.Salary, 90);
var stdDevAge = employees.StandardDeviation(e => e.Age);
// 滚动统计(用于时间序列分析)
var rollingAverages = dailySales
.OrderBy(d => d.Date)
.RollingAverage(d => d.Amount, windowSize: 7); // 7天移动平均
using Cyclops.Linq;
// 批量处理(避免大数据集内存问题)
var batchResults = largeDataSet
.Batch(1000) // 每批1000条
.Select(batch => ProcessBatch(batch))
.ToList();
// 集合运算
var commonElements = list1.Intersection(list2);
var uniqueElements = list1.UnionDistinct(list2);
var differentElements = list1.Difference(list2);
// 验证包含关系
bool hasAllRequiredRoles = userRoles.ContainsAll(requiredRoles);
bool hasAnyAdminRole = userRoles.ContainsAny(adminRoles);
// 条件集合选择
var resultList = sourceList.IfEmpty(fallbackList);
using Cyclops.Linq;
// 异步过滤和投影
var activeCustomers = await customers
.WhereAsync(async c => await IsCustomerActiveAsync(c.Id))
.SelectAsync(async c => await MapToCustomerDtoAsync(c))
.ToListAsync();
// 异步集合处理
var processedResults = await items
.ParallelForEachAsync(async item => {
return await ProcessItemAsync(item);
}, maxDegreeOfParallelism: 10);
// 异步聚合
bool allProcessed = await tasks.AllAsync(async t => await IsTaskProcessedAsync(t.Id));
int pendingCount = await tasks.CountAsync(async t => await IsTaskPendingAsync(t.Id));
延迟执行特性:
性能考虑:
异常处理:
数据库查询注意事项:
线程安全:
避免常见陷阱:
我们欢迎社区贡献!如果您有任何想法或建议,欢迎提交 Issue 或 Pull Request。
MIT License
Cyclops.Linq - 让数据查询和处理变得简单高效,为企业应用提供强大的LINQ增强能力!✨
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on TJC.Cyclops.Linq:
| Package | Downloads |
|---|---|
|
TJC.Cyclops.Orm
企服版框架中ORM核心,基于YitIdHelper、Mapster、SqlSugar封装 |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.6.11.2 | 340 | 6/11/2026 |
| 2026.6.11.1 | 369 | 6/11/2026 |
| 2026.6.9.4 | 374 | 6/9/2026 |
| 2026.6.9.3 | 365 | 6/9/2026 |
| 2026.6.9.2 | 364 | 6/9/2026 |
| 2026.6.9.1 | 355 | 6/9/2026 |
| 2026.6.8.3 | 373 | 6/8/2026 |
| 2026.6.8.2 | 320 | 6/8/2026 |
| 2026.6.8.1 | 321 | 6/8/2026 |
| 2026.6.5.1 | 293 | 6/5/2026 |
| 2026.5.18.1 | 273 | 5/18/2026 |
| 2026.5.11.1 | 281 | 5/11/2026 |
| 2026.5.7.2 | 303 | 5/7/2026 |
| 2026.5.7.1 | 304 | 5/7/2026 |
| 2026.4.29.2 | 249 | 4/29/2026 |
| 2026.4.29.1 | 245 | 4/29/2026 |
| 2026.4.27.1 | 220 | 4/27/2026 |
| 2026.4.24.2 | 213 | 4/24/2026 |
| 2026.4.24.1 | 206 | 4/24/2026 |
| 2026.4.14.2 | 234 | 4/14/2026 |
Cyclops.Framework中动态linq的处理库