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" />
<PackageReference Include="Levge.Extensions" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=Levge.Extensions&version=2.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
- StringExtensions
- EnumerableExtensions
- DateTimeExtensions
- ObjectExtensions
- TaskExtensions
- Bağımlılıklar
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 | Versions 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.
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.7)
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.