| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
The foundational core of the PowerCSharp ecosystem, providing centralized interfaces, models, and base functionality for all PowerCSharp packages. This package has been refactored to provide a clean, dependency-free foundation with improved architectural separation.
PowerCSharp.Core serves as the architectural foundation for the entire PowerCSharp ecosystem:
All interfaces are centralized in PowerCSharp.Core to maintain proper architectural separation:
dotnet add package PowerCSharp.CoreNamespace: PowerCSharp.Core.Interfaces.Extensions.Configuration
Represents the interface for application options.
public interface IAppOptions
{
string ConfigSectionPath { get; }
}Usage Example:
using PowerCSharp.Core.Interfaces.Extensions.Configuration;
public class MyAppOptions : IAppOptions
{
public string ConfigSectionPath => "MyApp";
public string ApiKey { get; set; }
public int Timeout { get; set; }
}Namespace: PowerCSharp.Core.Interfaces.Extensions.Linq
Implement a Service Provider for dynamically filtering of the type T using Dynamic Expressions.
public interface IDynamicFilterProvider<T>
{
void SetFilter(Func<T, bool> filter);
Func<T, bool> GetFilter();
}Namespace: PowerCSharp.Core.Interfaces.Extensions.Linq
Implement a Service Provider for dynamically ordering of the type T using Dynamic Expressions.
public interface IDynamicOrderProvider<T>
{
void SetOrderDelegates(List<(Func<T, object>, bool)> delegates);
List<(Func<T, object>, bool)> GetOrderDelegates();
}Usage Example:
using PowerCSharp.Core.Interfaces.Extensions.Linq;
// Create a dynamic filter provider
var filterProvider = new DynamicFilterProvider<Person>();
filterProvider.SetFilter(person => person.Age > 18 && person.Name.Contains("John"));
// Create a dynamic order provider
var orderProvider = new DynamicOrderProvider<Person>();
orderProvider.SetOrderDelegates(new List<(Func<Person, object>, bool)>
{
(person => person.Name, false), // Ascending by Name
(person => person.Age, true) // Descending by Age
});PowerCSharp.Core has no external dependencies, making it lightweight and ideal for inclusion in any project.
Other PowerCSharp packages reference PowerCSharp.Core for:
using PowerCSharp.Extensions;
using PowerCSharp.Core.Interfaces.Extensions.Linq;
// Your custom filter implementation
public class PersonFilterProvider : IDynamicFilterProvider<Person>
{
private Func<Person, bool> _filter;
public void SetFilter(Func<Person, bool> filter) => _filter = filter;
public Func<Person, bool> GetFilter() => _filter ?? (p => true);
}
// Use with PowerCSharp.Extensions
var people = new List<Person>();
var filtered = people.Filter(new PersonFilterProvider());using Microsoft.Extensions.Configuration;
using PowerCSharp.Extensions;
using PowerCSharp.Core.Interfaces.Extensions.Configuration;
public class DatabaseOptions : IAppOptions
{
public string ConfigSectionPath => "Database";
public string ConnectionString { get; set; }
public int Timeout { get; set; }
}
// Usage in application
var config = new ConfigurationBuilder().Build();
var dbOptions = config.GetOptions<DatabaseOptions>("Database");PowerCSharp.Core includes comprehensive unit tests. Run tests with:
dotnet test src/PowerCSharp.Core.TestsContributions are welcome! Please read our Contributing Guidelines for details.
This project is licensed under the MIT License - see the LICENSE file for details.
PowerCSharp.Core - The foundation of powerful C# development! 🚀
| Back | FazBrowse Home | New Git URL |