Levge.Extensions 2.3.0

dotnet add package Levge.Extensions --version 2.3.0
                    
NuGet\Install-Package Levge.Extensions -Version 2.3.0
                    
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="Levge.Extensions" Version="2.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Levge.Extensions" Version="2.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Levge.Extensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Levge.Extensions --version 2.3.0
                    
#r "nuget: Levge.Extensions, 2.3.0"
                    
#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.
#:package Levge.Extensions@2.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Levge.Extensions&version=2.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Levge.Extensions&version=2.3.0
                    
Install as a Cake Tool

Publish NuGet Package

Levge.Extensions

.NET 10 uygulamaları için günlük geliştirme ihtiyaçlarını karşılayan extension method koleksiyonu.
DI kaydı gerektirmez — using Levge.Extensions; yeterlidir.

İçindekiler


Kurulum

dotnet add package Levge.Extensions

StringExtensions

using Levge.Extensions;
Metot Açıklama
IsNullOrEmpty() string.IsNullOrEmpty kısayolu
IsNullOrWhiteSpace() string.IsNullOrWhiteSpace kısayolu
Truncate(maxLength, suffix?) Belirtilen uzunlukta keser, sonuna "..." ekler
ToCamelCase() PascalCase / snake_case / kebab-case → camelCase
ToSlug() URL-safe slug üretir
ToBase64Url() URL-safe Base64'e kodlar (padding yok)
FromBase64Url() URL-safe Base64'ten çözer
// Null / boşluk kontrolü
string? name = null;
name.IsNullOrEmpty();        // true
"  ".IsNullOrWhiteSpace();   // true

// Kırpma (log mesajı, başlık vb.)
"Bu çok uzun bir açıklama metnidir".Truncate(20); // "Bu çok uzun bir açı..."

// camelCase dönüşümü (API field normalizasyonu)
"UserName".ToCamelCase();     // "userName"
"tenant_name".ToCamelCase();  // "tenantName"
"X-Device-Id".ToCamelCase();  // "xDeviceId"

// Slug (URL, SEO)
"Merhaba Dünya!".ToSlug();   // "merhaba-dnya"
"Hello World 2025".ToSlug(); // "hello-world-2025"

// Base64 URL (token aktarımı, e-posta linkleri)
var token = "my-secret-token".ToBase64Url();   // "bXktc2VjcmV0LXRva2Vu"
var back  = token.FromBase64Url();             // "my-secret-token"

EnumerableExtensions

Metot Açıklama
IsNullOrEmpty() Koleksiyon null veya boş mu
Batch(size) Koleksiyonu eşit parçalara böler
Paginate(page, pageSize) Sayfa numarası ve boyutuna göre dilimler
ForEach(action) Her eleman için eylem çalıştırır
// Null / boş koleksiyon kontrolü
List<int>? items = null;
items.IsNullOrEmpty(); // true
new List<int>().IsNullOrEmpty(); // true

// Toplu işlem — batch insert, e-posta gönderimi vb.
var userIds = Enumerable.Range(1, 250);
foreach (var batch in userIds.Batch(50))
{
    await _repo.BulkInsertAsync(batch); // 50'şer kayıt
}

// Sayfalama (in-memory)
var page = allOrders.Paginate(page: 2, pageSize: 20);

// ForEach
users.ForEach(u => u.IsActive = false);

DateTimeExtensions

Metot Açıklama
ToUnixTimestamp() Unix epoch saniyesine çevirir
IsExpired() DateTime.UtcNow >= expiry kontrolü
StartOfDay() 00:00:00.000
EndOfDay() 23:59:59.9999999
// Unix timestamp (JWT iat/exp, log korelasyonu)
DateTime.UtcNow.ToUnixTimestamp(); // örn. 1714220400

// Token / kod geçerlilik kontrolü
var codeExpiry = DateTime.UtcNow.AddMinutes(15);
codeExpiry.IsExpired(); // false (henüz geçmedi)

// Gün aralığı sorguları
var start = DateTime.Today.StartOfDay(); // 2025-04-27 00:00:00
var end   = DateTime.Today.EndOfDay();   // 2025-04-27 23:59:59.9999999

var todayOrders = orders.Where(o => o.CreatedAt >= start && o.CreatedAt <= end);

ObjectExtensions

Metot Açıklama
DeepClone<T>() JSON üzerinden derin kopya oluşturur
ToJson(options?) Nesneyi JSON string'e çevirir
IsOneOf(values) Değer listesinden birine eşit mi
As<T>() Güvenli tip dönüşümü (as operatörü)
// Derin kopya (DTO dönüşümleri, test senaryoları)
var clone = originalConfig.DeepClone();

// JSON serializasyon (loglama, debug)
_logger.LogDebug(request.ToJson());

// Değer kümesi kontrolü
if (order.Status.IsOneOf(OrderStatus.Pending, OrderStatus.Processing))
    await NotifyAsync(order);

// Güvenli cast
var admin = user.As<AdminUser>(); // null döner, exception fırlatmaz

TaskExtensions

Metot Açıklama
FireAndForget() Beklemeden çalıştır — hata yutulmaz, loglanır
FireAndForget(logger) Logger ile fire-and-forget
FireAndForget(context) Bağlam adıyla fire-and-forget
FireAndForget(logger, context) Logger + bağlam adıyla fire-and-forget
TimeoutAfter(timeout) Süre aşımında TimeoutException fırlatır
OnFailure(action) Hata durumunda eylem çalıştırır, hatayı yeniden fırlatır
WhenAll() Koleksiyondaki tüm görevleri bekler
// Fire-and-forget (bildirim gönderimi, audit log vb.)
_notificationService.SendAsync(userId).FireAndForget(_logger, "SendNotification");

// Zaman aşımı
try
{
    await externalApiCall.TimeoutAfter(TimeSpan.FromSeconds(10));
}
catch (TimeoutException)
{
    _logger.LogWarning("Harici API zaman aşımına uğradı.");
}

// Hata yakalama + yeniden fırlatma
await _repo.SaveAsync()
    .OnFailure(ex => _logger.LogError(ex, "Kayıt başarısız."));

// Paralel görev bekleme
var tasks = users.Select(u => _emailService.SendAsync(u.Email));
await tasks.WhenAll();

Bağımlılıklar

Paket Amaç
Microsoft.Extensions.Logging.Abstractions TaskExtensions.FireAndForget için ILogger desteği
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Levge.Extensions:

Package Downloads
Levge.Notification.Email

Email notification infrastructure with provider-based extensibility

Levge.Notification.Push

Push notification infrastructure with provider-based extensibility. Supports Firebase, Fake, and custom providers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.3.0 97 4/29/2026
2.2.0 99 4/29/2026
2.1.0 97 4/27/2026
2.0.1 98 4/27/2026
1.1.45 119 1/22/2026
1.1.41 212 6/22/2025
1.1.40 193 6/22/2025
1.1.3 190 6/21/2025
1.1.2 174 6/21/2025
1.1.1 182 6/21/2025
1.1.0 265 6/18/2025
1.0.1 269 6/16/2025
1.0.0 223 6/16/2025