CoreOne 1.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CoreOne --version 1.3.0
                    
NuGet\Install-Package CoreOne -Version 1.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="CoreOne" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CoreOne" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="CoreOne" />
                    
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 CoreOne --version 1.3.0
                    
#r "nuget: CoreOne, 1.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 CoreOne@1.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=CoreOne&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=CoreOne&version=1.3.0
                    
Install as a Cake Tool

CoreOne

A modern, high-performance C# utility library designed to make your life easier.

.NET NuGet License Tests Coverage

CoreOne is a comprehensive utility library that provides battle-tested patterns, reactive extensions, and powerful helpers for building robust .NET applications. It eliminates boilerplate code and provides intuitive APIs for common programming tasks.

๐Ÿš€ Why CoreOne?

Write Less, Do More

Stop reinventing the wheel. CoreOne provides production-ready implementations of common patterns so you can focus on building features, not infrastructure.

Modern C# Features

Built with the latest C# language features including:

  • Primary constructors
  • Collection expressions []
  • Pattern matching & switch expressions
  • Nullable reference types
  • ValueTask for high-performance async operations

Multi-Framework Support

Targets .NET 10.0, .NET 9.0, .NET Standard 2.0, and 2.1 - use it anywhere.

๐Ÿ“ฆ Installation

dotnet add package CoreOne

โœจ Key Features

๐ŸŽฏ Hub: Lightweight Event Bus

A powerful pub/sub messaging system for decoupled communication within your application.

// Subscribe to messages
Hub.Global.Subscribe<OrderCreated>(async order => {
    await SendConfirmationEmail(order);
});

// Publish messages
Hub.Global.Publish(new OrderCreated(orderId: 123));

// State management
Hub.Global.Publish(new UserState { IsLoggedIn = true });
var currentState = Hub.Global.GetState<UserState>();

// Intercept messages before delivery
Hub.Global.Intercept<PaymentMessage>(async msg => {
    if (!await ValidatePayment(msg))
        return ResultType.Fail; // Prevent delivery
    return ResultType.Success;
}, order: 1, token);

Why you'll love it:

  • โœ… Global or scoped hubs
  • โœ… State management built-in
  • โœ… Message interception
  • โœ… Filtering and ordering
  • โœ… Async-first design
  • โœ… Zero external dependencies (just DI abstractions)

๐Ÿ”„ Reactive Extensions

Powerful observable streams inspired by ReactiveX, with familiar LINQ-like operators.

// Create observable from events
var clicks = Observable.FromEvent<MouseEventArgs>(
    h => button.Click += h,
    h => button.Click -= h
);

// Transform streams
clicks
    .Throttle(TimeSpan.FromMilliseconds(300))  // Debounce clicks
    .Select(e => e.Location)
    .Where(loc => loc.X > 100)
    .Subscribe(location => Console.WriteLine($"Click at {location}"));

// BehaviorSubject - always has a current value
var currentUser = new BehaviorSubject<User>(User.Guest);
currentUser.Subscribe(user => UpdateUI(user));
currentUser.OnNext(authenticatedUser);

Operators included:

  • Select, Where, Distinct, Throttle
  • Hub integration: hub.ToObservable<T>()

โœ… Result Pattern

Elegant error handling without exceptions. Compose operations with functional-style chaining.

// Basic result
public IResult<User> GetUser(int id)
{
    if (id <= 0)
        return Result.Fail<User>("Invalid ID");
    
    var user = _repository.Find(id);
    return new Result<User>(user);
}

// Functional composition
var result = await ValidateInput(request)
    .PipeResultAsync(() => SaveToDatabase(request))
    .SelectAsync(saved => MapToDto(saved))
    .OnSuccessAsync(dto => SendNotification(dto));

if (result.Success)
    return Ok(result.Model);
else
    return BadRequest(result.Message);

Features:

  • โœ… Result.Ok, Result.Fail(), Result.FromException()
  • โœ… Generic IResult<T> with model payload
  • โœ… Functional operators: Select, PipeResult, OnSuccess
  • โœ… Async extensions: SelectAsync, OnSuccessAsync
  • โœ… HTTP status code support via IResult<TModel, TStatus>

๐Ÿ—‚๏ธ Enhanced Collections

Type-safe, performant collections with rich APIs.

// Data<K,V> - Dictionary with default values and fluent API
var cache = new Data<string, User> {
    DefaultKey = "guest"
};
cache.Set("admin", adminUser);
var user = cache["unknown"]; // Returns guest user via DefaultKey

// DataList<K,V> - Dictionary of lists
var usersByRole = new DataList<string, User>();
usersByRole.Add("Admin", adminUser);
usersByRole.Add("Admin", superAdmin);
var admins = usersByRole["Admin"]; // Returns list of admins

// ConcurrentSet<T> - Thread-safe set with collection initializer
var activeUsers = new ConcurrentSet<string> {
    "user1",
    "user2",
    "user3"
};
activeUsers.Add("user4"); // Thread-safe add
activeUsers.Each(user => Console.WriteLine(user)); // Safe enumeration

// ImmutableList<T> - Thread-safe collections
var observers = ImmutableList<IObserver<T>>.Empty;
observers = observers.Add(newObserver); // Creates new instance

๐Ÿ”ง Rich Extension Methods

Over 33 extension classes covering strings, enumerables, dates, dictionaries, types, models, and more.

// String extensions
"HelloWorld".Separate(" ") // "hello world"
"user@example.com".ContainsX("EXAMPLE") // true (case-insensitive)
"test".MatchesAny("test", "demo", "prod") // true

// Enumerable extensions
items.ExcludeNulls() // Filter out nulls
items.Each(item => Process(item)) // Iterate with action
await items.EachAsync(async item => await Process(item))
items.Partition(10) // Split into chunks
items.ToData(x => x.Id) // Convert to Data<K,V>
items.AggregateResultAsync(seed, async (acc, item) => await Process(acc, item))

// Type extensions
typeof(User).AttributeExists<RequiredAttribute>() // Check for attribute
typeof(User).GetDefault() // Get default value
typeof(User).Implements(typeof(IEntity<>)) // Check generic interface
typeof(User).IsNullable() // Check if nullable

// Member extensions
property.GetAttribute<DisplayAttribute>() // Get attribute from member
property.AttributeExists<RequiredAttribute>() // Check member attribute

// Model extensions
model.ValidateModel() // Validate with data annotations
model.ToODictionary() // Convert to dictionary

// Delegate extensions
action.AsTask() // Convert Action to Func<Task>

// Query extensions (IQueryable)
query.OrderBy("Name", SortDirection.Ascending) // Dynamic ordering
query.Paginate(page: 1, pageSize: 20) // Pagination helper

// Result extensions
result.OnSuccess(() => LogSuccess())
await result.SelectAsync(model => TransformAsync(model))
result.PipeResult(() => NextOperation())

// DateTime extensions
date.CalculateAge() // Get age from date
date.StartOfWeek() // First day of week
date.TimeAgo() // "2 hours ago"

โšก Async Task Queue

Control concurrency and ensure sequential execution of async operations.

var queue = new AsyncTaskQueue(concurrency: 3);

// Enqueue work - executes with controlled concurrency
await queue.Enqueue(async () => {
    await ProcessExpensiveOperation();
});

// Sequential processing (concurrency: 1)
var serialQueue = new AsyncTaskQueue(concurrency: 1);
await serialQueue.Enqueue(() => UpdateDatabase()); // Guaranteed order
await serialQueue.Enqueue(() => SendNotification());

๐Ÿงต Thread Safety

Simple, safe synchronization primitives.

// SafeLock - simplified locking with using pattern
private readonly SafeLock Sync = new();

using (Sync.EnterScope())
{
    // Critical section - thread-safe
    _observers = _observers.Add(newObserver);
}

// Tokens for cancellation management
var token = AToken.Create(); // Auto-disposing token
var stoken = SToken.Create(); // Simple cancellation token

๐Ÿ” Reflection Utilities

High-performance reflection with caching.

// Get metadata about types
var metadata = MetaType.GetMetadata<User>(nameof(User.Email));
var value = metadata.GetValue(userInstance);

// Invoke methods dynamically (cached for performance)
var invoker = MetaType.GetInvokeMethod(typeof(MyClass), "MethodName");
var result = invoker.Invoke(instance, [arg1, arg2]);

// Type utilities
Types.Parse<int>("123") // IResult<int>
Types.IsNullable<int?>() // true
var defaultValue = typeof(User).GetDefault();

๐Ÿ“„ Pagination & Filtering

Built-in support for OData-style queries and pagination.

// PageRequest for pagination and filtering
var request = new PageRequest(currentPage: 1, pageSize: 20)
    .FilterBy("Active", "Status")
    .OrderBy("Name", SortDirection.Ascending);

// Build OData queries
var builder = new ODataBuilder();
builder.Url("api/users")
    .FilterBy(BinaryOperator.Equal, $"IsActive eq true")
    .OrderBy(new OrderBy("LastName", SortDirection.Ascending))
    .Top(50);
var query = builder.ToString();

๐ŸŽฒ Utilities

Common operations made easy.

// JSON serialization (Newtonsoft.Json)
var json = Utility.Serialize(user);
var user = Utility.DeserializeObject<User>(json);
var result = Utility.SerializeToStream(user, stream);

// Hashing
var hash = Utility.HashSHA256("password");
var crc = Utility.Crc32("data");
var encoded = Utility.ToBase64("text");

// Safe execution
var result = Utility.Try(() => RiskyOperation()); // IResult
var result = await Utility.Try(async () => await AsyncOperation());

// Phone formatting
Utility.FormatPhoneNumber("1234567890") // "(123) 456-7890"
Utility.FormatPhoneNumber("1234567890", mask: true) // "(***) ***-7890"

๐ŸŽจ Lookup Types

Type-safe enumerations with rich metadata.

public class OrderStatus : LookupType<OrderStatus>
{
    public static readonly OrderStatus Pending = new("PENDING", "Awaiting Processing");
    public static readonly OrderStatus Completed = new("COMPLETED", "Order Completed");
    public static readonly OrderStatus Cancelled = new("CANCELLED", "Order Cancelled");
}

// Usage
var status = OrderStatus.FindType("PENDING");
var allStatuses = OrderStatus.Items; // All defined statuses

๐Ÿ—๏ธ Base Classes

Foundation classes following SOLID principles.

// Disposable - proper disposal pattern
public class MyResource : Disposable
{
    protected override void OnDispose()
    {
        // Cleanup logic
    }
}

// BaseService - DI-ready service base class
public class UserService : BaseService
{
    [Service] private IRepository<User> Repository { get; init; }
    [Service(Optional = true)] private ILogger<UserService>? Logger { get; init; }
    
    public UserService(IServiceProvider services) : base(services) { }
    
    protected override async ValueTask DisposeAsync(bool disposing)
    {
        // Async cleanup
    }
}

๐Ÿ›๏ธ Architecture & SOLID Principles

CoreOne is built following SOLID principles:

  • Single Responsibility: Each class has one focused purpose (Hub for messaging, Subject for observables)
  • Open/Closed: Extension methods and virtual hooks allow extension without modification
  • Liskov Substitution: Rich interface hierarchies (IResult<T>, IObservable<T>)
  • Interface Segregation: Small, focused interfaces (IHub, IObserver<T>)
  • Dependency Inversion: Constructor injection and service provider integration

See .github/copilot-instructions.md for detailed coding guidelines.

๐Ÿ“š Documentation

Namespaces Overview

Namespace Purpose
CoreOne Core utilities, pooling, ID generation
CoreOne.Hubs Event bus and pub/sub messaging
CoreOne.Reactive Observable streams and reactive extensions
CoreOne.Results Result pattern for error handling
CoreOne.Collections Enhanced dictionary and list types
CoreOne.Extensions Extension methods for common types
CoreOne.Reflection High-performance reflection utilities
CoreOne.Operations Pagination, filtering, and query building
CoreOne.Threading Thread safety and async utilities
CoreOne.Services Base classes for DI-enabled services
CoreOne.Lookups Type-safe enumeration patterns
CoreOne.Attributes Custom attributes for DI and validation

๐ŸŽฏ Common Scenarios

Scenario 1: Decoupled Event Handling

// In your order service
public class OrderService
{
    public async Task<IResult> CreateOrder(OrderRequest request)
    {
        var order = new Order(request);
        await _repository.Save(order);
        
        // Publish event - other services will react
        Hub.Global.Publish(new OrderCreated(order.Id));
        
        return Result.Ok;
    }
}

// In your email service - completely decoupled
public class EmailService
{
    public EmailService(IHub hub)
    {
        hub.Subscribe<OrderCreated>(async evt => 
            await SendOrderConfirmation(evt.OrderId));
    }
}

Scenario 2: Safe API Calls

public async Task<IResult<CustomerDto>> GetCustomerAsync(int id)
{
    return await ValidateId(id)
        .PipeResultAsync(() => _repository.GetAsync(id))
        .SelectAsync(customer => _mapper.Map(customer))
        .OnSuccessAsync(dto => _cache.SetAsync(id, dto));
}

// Clean controller action
public async Task<IActionResult> GetCustomer(int id)
{
    var result = await _service.GetCustomerAsync(id);
    return result.Success ? Ok(result.Model) : NotFound(result.Message);
}

Scenario 3: Reactive UI Updates

public class DashboardViewModel
{
    private readonly BehaviorSubject<DashboardData> _data = new(DashboardData.Empty);
    
    public IObservable<DashboardData> Data => _data;
    
    public void Initialize()
    {
        // Subscribe to real-time updates from Hub
        Hub.Global.ToObservable<DashboardData>()
            .Subscribe(data => _data.OnNext(data));
    }
}

๐Ÿงช Testing & Quality

CoreOne maintains high code quality with 779 comprehensive tests providing 57% line coverage:

Coverage by Component

  • Extensions (13 classes): 95%+ coverage

    • DelegateExtensions: 100%
    • MemberExtensions: 100%
    • ModelExtensions: 97.7%
    • ObjectExtensions: 100%
    • QueryExtensions: 95.8%
    • StringExtensions: 97.7%
    • TypeExtensions: 97.8%
    • EnumerableExtensions: 93.6%
  • Collections: 95%+ coverage

    • Data<T1,T2>: 100%
    • DataList<T1,T2>: 100%
    • ConcurrentSet<T>: 95.1%
    • DataCollection: 95.4%
  • Core Infrastructure: Excellent coverage

    • Hub System: 88.9%
    • Subject<T>: 100%
    • BehaviorSubject<T>: 100%
    • Observable: 90.4%
    • Result: 100%
    • Types: 96%
    • MetaType: 92.6%
  • Services & DI:

    • ModelTransaction: 91.7%
    • TargetCreator: 80.7%
    • BaseService: 65.3%
    • ServiceInitializer: 62.8%

Testing Infrastructure

  • Framework: NUnit 4.3.2 with modern async test patterns
  • Mocking: Moq for dependency injection and callbacks
  • Coverage: Coverlet MSBuild 6.0.4 with ReportGenerator
  • Patterns: Comprehensive null handling, edge cases, thread safety, and async scenarios

See COVERAGE_REPORT.md for detailed metrics and coverage goals.

# Run tests
dotnet test

# Run with coverage
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura

# Generate coverage report
reportgenerator -reports:Tests/TestResults/coverage.cobertura.xml \
    -targetdir:Tests/TestResults/CoverageReport -reporttypes:Html

๐Ÿ“‹ Requirements

  • .NET 9.0+ or .NET Standard 2.0+
  • C# 12 (for latest features)

Dependencies

  • Microsoft.Extensions.DependencyInjection.Abstractions - For DI integration
  • Microsoft.Extensions.Logging.Abstractions - For logging
  • Newtonsoft.Json - For JSON serialization
  • System.Text.Json - For modern JSON support

๐Ÿค Contributing

Contributions are welcome! Please follow the coding guidelines in .github/copilot-instructions.md.

Coding Standards

  • PascalCase for all members (including private fields)
  • Primary constructors preferred
  • Expression-bodied members for simple implementations
  • Async/await throughout
  • SOLID principles enforced
  • Comprehensive testing with NUnit patterns

Testing Standards

  • Test file structure: No [TestFixture] attribute, public classes only
  • Naming: MethodName_Scenario_ExpectedBehavior pattern
  • Assertions: NUnit fluent syntax with Assert.That
  • Async tests: TaskCompletionSource for synchronization
  • Mocking: Moq with proper callback patterns
  • Coverage areas: Happy path, null handling, edge cases, thread safety

See the Testing Guidelines section for comprehensive test patterns and examples.

๐Ÿ“„ License

This project is licensed under the MIT License.

๐Ÿ‘ค Author

Juan Lopez


Built with โค๏ธ using modern C# โ€ข Multi-framework support โ€ข Production-ready โ€ข Open Source

Product 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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on CoreOne:

Package Downloads
CoreOne.ModelPatch

Package Description

CoreOne.Winforms

Package Description

CoreOne.Identity

Package Description

CoreOne.Drawing

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.0.3 0 4/6/2026
1.4.0.2 35 4/6/2026
1.4.0.1 51 3/30/2026
1.4.0 42 3/26/2026
1.3.2.4 63 3/4/2026
1.3.2.3 47 2/25/2026
1.3.2.2 42 2/25/2026
1.3.2.1 46 2/25/2026
1.3.2 51 2/24/2026
1.3.1.2 54 2/20/2026
1.3.1.1 50 2/20/2026
1.3.1 58 2/6/2026
1.3.0 117 1/23/2026
1.2.2 58 1/22/2026
1.2.1 57 1/22/2026
1.2.0 155 11/28/2025
1.1.3 87 11/28/2025
1.1.2.2 82 10/12/2025
1.1.2.1 144 10/6/2025
1.1.2 200 10/2/2025
Loading failed