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 | 68 | 11/27/2024 |
2.6.1 | 191 | 11/8/2024 |
2.5.0 | 314 | 11/16/2023 |
2.4.0 | 2,475 | 4/16/2022 |
2.3.0 | 427 | 3/25/2022 |
2.3.0-preview | 178 | 3/25/2022 |
2.2.7 | 676 | 3/30/2021 |
2.2.6 | 321 | 3/22/2021 |
2.2.4 | 394 | 3/11/2021 |
2.2.2 | 345 | 3/11/2021 |
2.2.2-preview | 228 | 3/11/2021 |
2.2.1 | 572 | 3/8/2020 |
2.2.0 | 484 | 2/6/2020 |
2.1.3 | 461 | 12/22/2019 |
2.1.1 | 882 | 1/21/2019 |
2.1.0 | 862 | 1/16/2019 |
2.0.1 | 1,157 | 1/14/2019 |
2.0.0 | 5,366 | 1/13/2019 |
1.0.1 | 838 | 1/10/2019 |
1.0.0 | 1,998 | 1/9/2019 |