Yozian.Extension
2.6.3
dotnet add package Yozian.Extension --version 2.6.3
NuGet\Install-Package Yozian.Extension -Version 2.6.3
<PackageReference Include="Yozian.Extension" Version="2.6.3" />
paket add Yozian.Extension --version 2.6.3
#r "nuget: Yozian.Extension, 2.6.3"
// Install Yozian.Extension as a Cake Addin #addin nuget:?package=Yozian.Extension&version=2.6.3 // Install Yozian.Extension as a Cake Tool #tool nuget:?package=Yozian.Extension&version=2.6.3
Useful Extension methods
You could take a look into test project to get examples with following list!
Extension methods of Type
-
DumpDetail
-
GetMemberName
-
AddWhen
RemoveWhen
-
SafeGet
-
ForEach
FlattenToString
-
WhereWhen
-
SafeToString
ConvertAll
ShallowClone
-
ToEnum
LimitLength
Repeat
-
ToPagination
ToPaginationAsync
Take IQueryable Extension method as example
conditional query where closure
The example shows the extension method WhereWhen
eliminate if statement block.
The constrain applied only when the condition matched, so that you could achieve dynamic query easily!
var books = await this.dbContext.Book
.Where(x => x.Name.Equals(request.Name))
.WhereWhen(
!string.IsNullOrEmpty(request.Category),
x => x.Category.Equals(request.Category)
)
.WhereWhen(
request.PublishDate.HasValue,
x => x.PublishDate.Equals(request.PublishDate)
)
.ToListAsync();
for old school way, would have lots of if statement block
var query = this.dbContext.Book
.Where(x => x.Name.Equals(request.Name));
if(!string.IsNullOrEmpty(request.Category)){
query = query.Where(x => x.Category.Equals(request.Category))
}
if(request.PublishDate.HasValue){
query = query.Where(x => x.PublishDate.Equals(request.PublishDate))
}
var books = await query.ToListAsync();
IQueryable Pagination
- An Extension method for IQueryable<T> interface
- Could apply on EntityFramework DbSet<T> query (Any implementation of IQueryable<T>)
var count = 10;
var size = 3;
var source = Enumerable
.Range(1, count)
.AsQueryable();
Pageable<int> result = source.ToPagination(1, size);
// Async
Pageable<int> result = await source.ToPaginationAsync(1, size);
Apply converter
var count = 10;
var size = 3;
var source = Enumerable
.Range(1, count)
.AsQueryable();
Pageable<int, string> result = source.ToPagination(1, size, x => x.ToString());
// Async
Pageable<int, string> result = await source.ToPaginationAsync(1, size, x => x.ToString());
Fetch next page for the same queryable source
var count = 10;
var size = 3;
var source = Enumerable
.Range(1, count)
.AsQueryable();
Pageable<int, string> result = source.ToPagination(1, size, x => x.ToString());
do
{
// process records here
result.Records.ForEach(it =>
{
// do somthing
});
result.FetchNextPage();
}
while (result.HasNextPage);
Fetch next page for the same queryable source
var count = 32;
var size = 3;
var source = Enumerable
.Range(1, count)
.AsQueryable();
var currentPage = 3;
var result = source.ToPagination(currentPage, size);
var pageSize = 5;
// converte to Page<T>, including navigation info.
Page<int> page = result.ToPage(pageSize);
// also provide tranform method to map records
Page<string> page = result.ToPage(pageSize, x => x.ToString());
// dump Page<int>
{
"TotalCount": 32,
"PageCount": 11,
"CurrentPage": 3,
"Size": 3,
"Records": [
7,
8,
9
],
"PageSize": 5,
"HasPreviosPages": false,
"HasNextPages": true,
"PreviosLastPageNo": 1,
"NextStartPageNo": 6,
"NavigationPages": [
1,
2,
3,
4,
5
]
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Yozian.Extension:
Package | Downloads |
---|---|
Yozian.DependencyInjectionPlus
Easy for DI register, Auto register services, Decorate service with attribute |
|
Yozian.EFCorePlus
partial updated and scheam description scripts generation |
|
Yozian.Validation
fluent strong type validation |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.6.3 | 83 | 11/27/2024 |
2.6.1 | 206 | 11/8/2024 |
2.5.0 | 323 | 11/16/2023 |
2.4.0 | 2,485 | 4/16/2022 |
2.3.0 | 429 | 3/25/2022 |
2.3.0-preview | 178 | 3/25/2022 |
2.2.7 | 678 | 3/30/2021 |
2.2.6 | 323 | 3/22/2021 |
2.2.4 | 396 | 3/11/2021 |
2.2.2 | 347 | 3/11/2021 |
2.2.2-preview | 228 | 3/11/2021 |
2.2.1 | 574 | 3/8/2020 |
2.2.0 | 486 | 2/6/2020 |
2.1.3 | 463 | 12/22/2019 |
2.1.1 | 884 | 1/21/2019 |
2.1.0 | 864 | 1/16/2019 |
2.0.1 | 1,159 | 1/14/2019 |
2.0.0 | 5,390 | 1/13/2019 |
1.0.1 | 840 | 1/10/2019 |
1.0.0 | 2,000 | 1/9/2019 |