Bikiran.Utils
1.0.8
dotnet add package Bikiran.Utils --version 1.0.8
NuGet\Install-Package Bikiran.Utils -Version 1.0.8
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="Bikiran.Utils" Version="1.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bikiran.Utils" Version="1.0.8" />
<PackageReference Include="Bikiran.Utils" />
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 Bikiran.Utils --version 1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bikiran.Utils, 1.0.8"
#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 Bikiran.Utils@1.0.8
#: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=Bikiran.Utils&version=1.0.8
#tool nuget:?package=Bikiran.Utils&version=1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bikiran.Utils
A comprehensive utility library for .NET development with debugging, API support, and configuration management
Installation
dotnet add package Bikiran.Utils
Features
Debugging Utilities
- 🖨️ Formatted console output with index tracking
- 🚨 Exception generation with JSON-formatted context
- 🔍 NuGet package version inspection
- 🎯 Simplified debugging workflows
API Response Handling
- ✅ Structured response models for REST APIs
- 🏭 Factory methods for success/error responses
- 🔗 Request correlation tracking
- 🛠️ Exception-to-response mapping
Exception Handling
- 🎯 Simplified exception creation with metadata
- 🏷️ Reference tracking for debugging context
- 🔧 Consistent exception formatting
IP Address Utilities
- 🌐 Client IP extraction from HTTP context
- 🔍 Proxy and CDN header support (Cloudflare, Nginx)
- 🔢 IP address format conversion (string/long)
- 🛡️ Robust fallback mechanisms
Configuration Management
- 🔑 Key-value pair modeling with metadata
- 🏷️ Typed configuration objects with defaults
- 🔒 Public/private access control
- 📋 ToString() override for diagnostics
Quick Start
Debugging Helpers
using Bikiran.Utils;
// Print indexed values
C.Print("App started", DateTime.UtcNow, Environment.Version);
// Throw with context
try {
riskyOperation();
}
catch {
C.X("Operation failed", "User ID: 1234", errorDetails);
}
Exception Creation
using Bikiran.Utils.Models;
// Create exception with reference
var exception = Excep.Create("Invalid user input", "UserService.ValidateUser");
throw exception;
// Exception will contain reference data for debugging
// exception.Data["Reference"] will be "UserService.ValidateUser"
IP Address Operations
using Bikiran.Utils.Models;
// In your ASP.NET Core controller or middleware
public IActionResult GetUserInfo()
{
// Get client IP as string (supports Cloudflare, Nginx proxies)
string clientIp = IpOperation.GetIpString(HttpContext);
// Get IP as long integer for database storage/comparison
long ipAsLong = IpOperation.GetIpLong(HttpContext);
return Ok(new { ClientIP = clientIp, IpNumeric = ipAsLong });
}
// Handles:
// - CF-Connecting-IP (Cloudflare)
// - X-Forwarded-For (Nginx/Proxy)
// - Direct connection IP fallback
API Response Handling
using Bikiran.Utils.Models.ApiResp;
// Successful response
return ApiResponseHandler.Success("User created", new { Id = 42, Username = "john" });
// Error response
return ApiResponseHandler.NotFound("User not found");
// Exception handling
try {
ProcessOrder();
}
catch (Exception ex) {
return ApiResponseHandler.BadRequest(ex);
}
Key-Value Configuration
using Bikiran.Utils.Models;
// Create a configuration entry
var config = new KeyObj
{
Key = "App.Theme.Color",
Title = "Application Color Scheme",
DefaultValue = "dark",
IsPublic = false
};
Console.WriteLine(config);
// Output: App.Theme.Color (Application Color Scheme) - Default: dark [Private]
Core Components
C
Class (Debugging)
// Print values with headers
C.Print("Configuration", configValue);
// Immediate error termination
C.X("Critical failure", errorContext);
Excep
Class (Exception Creation)
// Create exception with optional reference
var exception = Excep.Create("Error message", "Optional.Reference.Context");
// The exception will have:
// - Message: "Error message"
// - Data["Reference"]: "Optional.Reference.Context"
IpOperation
Class (IP Address Utilities)
// Get client IP address as string
string clientIp = IpOperation.GetIpString(httpContext);
// Get client IP address as long integer
long ipNumeric = IpOperation.GetIpLong(httpContext);
// Priority order for IP detection:
// 1. CF-Connecting-IP (Cloudflare)
// 2. X-Forwarded-For (Nginx/Proxy)
// 3. RemoteIpAddress (Direct connection)
ApiResponse
Model
public class ApiResponse {
public bool Error { get; set; }
public string Message { get; set; }
public object Data { get; set; }
public string ReferenceName { get; set; }
}
KeyObj
Configuration Model
public class KeyObj {
public string Key { get; set; } // Unique identifier
public string Title { get; set; } // Human-readable name
public object DefaultValue { get; set; } // Default value
public bool IsPublic { get; set; } // Visibility flag
}
Factory Methods Reference
Component | Method | Purpose | Example |
---|---|---|---|
IpOperation | GetIpString() |
Get client IP as string | GetIpString(HttpContext) |
GetIpLong() |
Get client IP as long integer | GetIpLong(HttpContext) |
|
Excep | Create() |
Create exception with reference | Create("Error", "Module.Method") |
ApiResponse | Success() |
Successful operation | Success("Created", data) |
Error() |
Generic error | Error("Validation failed") |
|
NotFound() |
404 equivalent | NotFound("User missing") |
|
BadRequest() |
400 equivalent | BadRequest(exception) |
|
KeyObj | (Constructor) | Create configuration entry | new KeyObj { ... } |
Documentation
- IntelliSense Support: Full XML documentation included
- API Reference: GitHub Wiki
- Samples: Example Projects directory
- Configuration Guide: KeyObj Usage
Contributing
We welcome contributions! Please:
- Fork the repository
- Create your feature branch
- Add tests for new functionality
- Submit a pull request
License
Distributed under the MIT License. See LICENSE for full terms.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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.
-
net9.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- NuGet.Protocol (>= 6.13.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.