Skip to content

This .Net8 DLL is designed to streamline and enhance the development process for C# projects by consolidating a variety of essential functions into a single, easy-to-use, and efficient library.

License

Notifications You must be signed in to change notification settings

Chookees/FunctionProvider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

53 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FunctionProvider

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.

πŸš€ Features

πŸ“Š Math Operations

Basic Math (FunctionProvider.Math.Basic)

  • 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)

Advanced Math (FunctionProvider.Math.Advanced)

  • 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

Sorting Algorithms (FunctionProvider.Math.Sort)

  • 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 & Directory Operations

File Operations (FunctionProvider.IO.File)

  • 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

Directory Operations (FunctionProvider.IO.Directory)

  • 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

πŸ”§ Utility Functions

String Manipulation (FunctionProvider.Various.StringManipulation)

  • 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

Validation (FunctionProvider.Various.Validation)

  • 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

Random Generation (FunctionProvider.Various.Random)

  • 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

GUID Operations (FunctionProvider.Various.GUID)

  • Generation: Create new GUIDs
  • Parsing: String to GUID conversion with validation
  • Validation: GUID format validation
  • Utilities: Hash code extraction, string conversion

πŸ“… Date & Time Operations

Date Operations (FunctionProvider.DateAndTime.DateOperations)

  • 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

πŸ“„ Data Processing

JSON Operations (FunctionProvider.Data.Json)

  • 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

🌐 Networking

HTTP Client (FunctionProvider.Networking.HttpClient)

  • 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

πŸ”’ Security

Encryption (FunctionProvider.Security.Encryption)

  • 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

πŸ› οΈ Installation

Prerequisites

  • .NET 8.0 or later
  • Visual Studio 2022 or later (recommended)

Setup

  1. Clone the repository:

    git clone https://github.com/yourusername/FunctionProvider.git
  2. Navigate to the project directory:

    cd FunctionProvider
  3. Build the solution:

    dotnet build
  4. Run tests (optional):

    cd unitTests
    dotnet test

πŸ“– Usage Examples

Basic Math Operations

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);

String Manipulation

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);

File Operations

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();

Date Operations

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);

JSON Processing

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);

HTTP Operations

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");

Security Operations

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");

πŸ§ͺ Testing

The project includes comprehensive unit tests using xUnit, Moq, and FluentAssertions:

cd unitTests
dotnet test

Test coverage includes:

  • All mathematical functions
  • String manipulation operations
  • File and directory operations
  • Date/time calculations
  • JSON processing
  • HTTP client functionality
  • Security operations

πŸ“‹ Dependencies

  • .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

πŸ—οΈ Architecture

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.Task access pattern

πŸ“ License

This project is licensed under the MIT License. See the LICENSE file for more information.

🀝 Contributing

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.

Development Guidelines

  1. Follow the existing code style and patterns
  2. Add comprehensive unit tests for new features
  3. Update documentation for any new functionality
  4. Ensure all tests pass before submitting

πŸ“ž Support

If you encounter any issues or have questions, please:

  1. Check the existing issues on GitHub
  2. Create a new issue with detailed information
  3. Include code examples and error messages when possible

πŸ”„ Version History

  • 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.

About

This .Net8 DLL is designed to streamline and enhance the development process for C# projects by consolidating a variety of essential functions into a single, easy-to-use, and efficient library.

Resources

License

Stars

Watchers

Forks