A comprehensive C# utility library that provides a collection of useful functions for mathematical calculations, string manipulation, validation, random number generation, file operations, date/time handling, JSON processing, networking, and security operations.
- Arithmetic: Power calculations, square roots, rounding to two decimal places
- Statistical Functions: Standard deviation, variance, median, mode, percentiles
- Matrix Operations: Determinant calculation, matrix inverse, linear system solving
- Advanced Calculations: Fibonacci sequence, factorial, binomial coefficient
- Constants: Pi (Ο) and Euler's number (e)
- Calculus: Tangent line calculation, derivatives, numerical integration (Trapezoidal Rule)
- Differential Equations: Heat equation and 2D wave equation solvers
- 3D Geometry: Torsion and curvature calculations for parametric curves
- Matrix Operations: Matrix multiplication, quadratic equation solving
- Complex Numbers: Full complex number arithmetic with magnitude and argument
- Permutations: Generate all permutations of arrays
- Comparison Sorts: Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort, Heap Sort, Shell Sort
- Non-Comparison Sorts: Radix Sort, Counting Sort
- All algorithms implemented with proper time complexity considerations
- File Management: Create, delete, copy, rename files
- Dynamic Writing: Stream-based file writing with real-time content modification
- File Reading: Read file contents as strings
- Path Management: Automatic path merging and validation
- Error Handling: Comprehensive return codes for all operations
- Drive Information: Get all drives, find drive with most free space
- File Discovery: Search for files by pattern, get all files recursively
- Directory Copying: Recursive directory copying with subdirectory support
- Text Formatting: CamelCase conversion, word frequency analysis
- Compression: GZip string compression and decompression
- Text Analysis: Palindrome detection, Levenshtein distance calculation
- Encoding: Base64 encoding/decoding, Caesar cipher encryption
- Data Validation: JSON and XML validation and formatting
- Pattern Matching: Regex search and replace operations
- Email Validation: RFC-compliant email address validation
- Phone Numbers: International phone number format validation
- URLs: HTTP/HTTPS URL validation
- Financial: IBAN and BIC validation with checksum verification
- Geographic: Postal code validation for multiple countries (DE, US, GB)
- Security: Strong password validation with complexity requirements
- Basic Random: Integers, doubles, strings with customizable ranges
- Advanced Random: Cryptographically secure random generation
- Data Structures: Random matrices, graphs, permutations
- Password Generation: Secure password generation with complexity options
- Date/Time: Random date and time generation within ranges
- Selection: Random element selection from lists and arrays
- Generation: Create new GUIDs
- Parsing: String to GUID conversion with validation
- Validation: GUID format validation
- Utilities: Hash code extraction, string conversion
- Age Calculation: Calculate age from birth date
- Date Arithmetic: Days between dates, business days calculation
- Calendar Functions: First/last day of month/year, leap year detection
- Timezone Support: Timezone conversion between different zones
- Business Logic: Business day calculations, weekend detection
- Time Ranges: Start/end of day, quarter and week number calculations
- Serialization: Object to JSON conversion with formatting options
- Deserialization: JSON to object conversion with type safety
- Validation: JSON format validation
- Formatting: Pretty-print and minify JSON
- Advanced Operations: JSON path extraction, merging, dictionary conversion
- HTTP Methods: GET, POST, PUT, DELETE requests
- JSON Support: Automatic JSON serialization/deserialization
- Authentication: Bearer token support
- Customization: Custom headers, timeout configuration
- Error Handling: Robust error handling with fallback responses
- AES Encryption: 256-bit AES encryption/decryption with key and IV generation
- Hashing: SHA-256 and MD5 hash computation
- Base64: Encoding and decoding operations
- Password Security: BCrypt password hashing and verification
- Secure Random: Cryptographically secure random string generation
- .NET 8.0 or later
- Visual Studio 2022 or later (recommended)
-
Clone the repository:
git clone https://github.com/yourusername/FunctionProvider.git
-
Navigate to the project directory:
cd FunctionProvider -
Build the solution:
dotnet build
-
Run tests (optional):
cd unitTests dotnet test
using FunctionProvider.Math;
// Statistical calculations
var basic = Basic.Task;
double[] values = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
double stdDev = basic.CalculateStandardDeviation(values);
double median = basic.Median(values);
double variance = basic.Variance(values);
Console.WriteLine($"Standard Deviation: {stdDev}");
Console.WriteLine($"Median: {median}");
Console.WriteLine($"Variance: {variance}");
// Matrix operations
double[,] matrix = { { 1, 2 }, { 3, 4 } };
double determinant = basic.Determinant(matrix);
double[,] inverse = basic.MatrixInverse(matrix);using FunctionProvider.Various;
var stringManip = StringManipulation.Task;
// Text analysis
string text = "Hello world, this is a test!";
var wordFreq = stringManip.WordFrequency(text);
string[] palindromes = stringManip.FindPalindromes("racecar level civic");
// Distance calculation
int distance = stringManip.LevenshteinDistance("kitten", "sitting");
// Encoding
string encoded = stringManip.Base64Encode("Hello World");
string decoded = stringManip.Base64Decode(encoded);using FunctionProvider.IO;
var file = File.Task;
// Create and write to file
string[] content = { "Line 1", "Line 2", "Line 3" };
ReturnCodes result = file.CreateFile(@"C:\temp\example.txt", content);
// Dynamic file writing
file.CreateWriter(@"C:\temp", "log", ".txt");
file.WriteLine("Application started");
file.WriteLine("Processing data...");
file.Close();using FunctionProvider.DateAndTime;
var dateOps = DateOperations.Task;
// Age calculation
DateTime birthDate = new DateTime(1990, 5, 15);
int age = dateOps.CalculateAge(birthDate);
// Business days
DateTime start = new DateTime(2024, 1, 1);
DateTime end = new DateTime(2024, 1, 31);
int businessDays = dateOps.BusinessDaysBetween(start, end);
// Timezone conversion
DateTime utcTime = DateTime.UtcNow;
TimeZoneInfo est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime estTime = dateOps.ConvertTimeZone(utcTime, TimeZoneInfo.Utc, est);using FunctionProvider.Data;
var json = Json.Task;
// Serialization
var person = new { Name = "John Doe", Age = 30, City = "New York" };
string jsonString = json.Serialize(person, indented: true);
// Deserialization
var deserializedPerson = json.Deserialize<Person>(jsonString);
// JSON operations
string extracted = json.ExtractValue(jsonString, "$.Name");
string merged = json.MergeJson(json1, json2);using FunctionProvider.Networking;
var httpClient = HttpClient.Task;
// GET request
string response = await httpClient.GetAsync("https://api.example.com/data");
// POST with JSON
var data = new { name = "John", email = "john@example.com" };
string postResponse = await httpClient.PostJsonAsync("https://api.example.com/users", data);
// Authentication
httpClient.SetBearerToken("your-jwt-token");using FunctionProvider.Security;
var encryption = Encryption.Task;
// Password hashing
string password = "mySecurePassword";
string hash = encryption.HashPassword(password);
bool isValid = encryption.VerifyPassword(password, hash);
// AES encryption
byte[] key = encryption.GenerateAesKey();
byte[] iv = encryption.GenerateAesIv();
string encrypted = encryption.EncryptAes("sensitive data", key, iv);
string decrypted = encryption.DecryptAes(encrypted, key, iv);
// Hashing
string sha256Hash = encryption.ComputeSha256Hash("data to hash");The project includes comprehensive unit tests using xUnit, Moq, and FluentAssertions:
cd unitTests
dotnet testTest coverage includes:
- All mathematical functions
- String manipulation operations
- File and directory operations
- Date/time calculations
- JSON processing
- HTTP client functionality
- Security operations
- .NET 8.0: Target framework
- BCrypt.Net-Next: Password hashing (v4.0.3)
- xUnit: Testing framework
- Moq: Mocking framework
- FluentAssertions: Test assertions
- coverlet.collector: Code coverage
The library follows a singleton pattern with lazy initialization for all utility classes:
public sealed class ExampleClass
{
private static readonly Lazy<ExampleClass> lazy = new Lazy<ExampleClass>(() => new ExampleClass());
public static ExampleClass Task { get { return lazy.Value; } }
private ExampleClass() { }
}This design ensures:
- Thread Safety: Lazy initialization is thread-safe
- Memory Efficiency: Single instance per class
- Easy Access: Simple
ClassName.Taskaccess pattern
This project is licensed under the MIT License. See the LICENSE file for more information.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Follow the existing code style and patterns
- Add comprehensive unit tests for new features
- Update documentation for any new functionality
- Ensure all tests pass before submitting
If you encounter any issues or have questions, please:
- Check the existing issues on GitHub
- Create a new issue with detailed information
- Include code examples and error messages when possible
- v1.0.0: Initial release with comprehensive utility functions
- Full feature set including math, I/O, validation, security, and networking operations
- Complete test coverage and documentation
FunctionProvider - Your comprehensive C# utility library for all common programming tasks.