OpenCode 3.2.0
Prefix Reserveddotnet add package OpenCode --version 3.2.0
NuGet\Install-Package OpenCode -Version 3.2.0
<PackageReference Include="OpenCode" Version="3.2.0" />
<PackageVersion Include="OpenCode" Version="3.2.0" />
<PackageReference Include="OpenCode" />
paket add OpenCode --version 3.2.0
#r "nuget: OpenCode, 3.2.0"
#:package OpenCode@3.2.0
#addin nuget:?package=OpenCode&version=3.2.0
#tool nuget:?package=OpenCode&version=3.2.0
OpenCode
OpenCode is a lightweight, cross-targeted .NET library providing useful extension methods for strings, numbers, booleans, GUIDs, and dates. It simplifies common tasks such as safe trimming, casing conversions, masking, parsing, numeric formatting, hashing, and more. The library targets .NET 8 through .NET 9.
Supported Targets
- .NET 8, .NET 9
Features
Core Helpers
NullIfEmpty— returnsnullfornull/empty/whitespace input.OrDefault— returns a specified default value when input isnull/empty/whitespace.SafeTrim— trims input safely; returns empty string if input isnull.Truncate— safely truncates a string to a maximum length.SafeSubstring— extracts substring without throwing exceptions for out-of-range indices.EqualsIgnoreCase— ordinal case-insensitive comparison.IsNumeric— checks if a string can be parsed as a number (decimal).
Formatting Helpers
ToTitleCase— title-cases each word using invariant culture.ToPascalCase,ToCamelCase— convert strings to PascalCase or camelCase, removing non-alphanumeric separators.ToSnakeCase,ToKebabCase— convert strings tosnake_caseorkebab-case.ToSlug— produces a URL-safe slug (diacritics removed, spaces → dashes).Mask— mask middle characters, leaving configurable head/tail visible.FormatWith— culture-invariant wrapper forstring.Format.
Utility Helpers
RemoveDiacritics— removes accent marks from characters.RemoveNonAlphanumeric— keeps only letters and digits.IsEmail— lightweight check for valid email format.IsJson— heuristic check for JSON-like input (starts/ends with{}or[]).
Numeric Helpers (Decimal & Integer)
ParseToDecimal,ParseToInt,ParseToLong— safe parsing with configurable defaults (invariant culture).RemoveTrailingZero— removes redundant trailing zeros (usesG29to preserve significance).IsDecimal,IsInteger— validate numeric strings.ToOrdinal— converts numeric string to English ordinal (e.g.,1→1st).
Boolean Helpers
ParseToBool— acceptstrue/false,1/0,yes/no,on/off, etc., with configurable default.IsBool— checks whether a string can be interpreted as boolean.ToYesNo— returns"Yes"or"No"based on parsed truthiness.
Hashing & Encoding
ToMD5Hash— computes MD5 hash (lowercase hex).ToSHA256Hash— computes SHA256 hash (Base64).ToBase64/FromBase64— encode/decode Base64 strings safely.
Guid Helpers
ParseToGuid,IsGuid,IsValidGuid— parse and validate GUIDs.ToShortGuid,ToCompactString— compact representations of GUIDs.
Date & Time Helpers
ParseToDateTime,ParseToDateOnly— safe parsing with default values.IsDateTime— check if string can be parsed to DateTime.ToFormattedDate— format parsed DateTime string.
Getting Started
Prerequisites
- .NET 8 SDK or later
- Visual Studio 2022 or later (or any editor/IDE supporting .NET)
Installation
Add a project reference to OpenCode or install the package from NuGet if published.
dotnet add package OpenCode
Usage Examples
using OpenCode;
// Remove trailing zeros
string compact = "2.5000".RemoveTrailingZero(); // "2.5"
// SHA256 hash
string hash = "Hello".ToSHA256Hash();
// Parse string to bool
bool isTrue = "yes".ParseToBool(); // true
// Check if string is boolean
bool validBool = "on".IsBool(); // true
// Parse string to int
int number = "123".ParseToInt(); // 123
// Convert string to PascalCase
string pascal = "hello world".ToPascalCase(); // "HelloWorld"
// Mask string
string masked = "1234567890".Mask(2, 2); // "12******90"
Testing
Automated tests are included in the OpenCode.Tests project.
Run tests using CLI:
dotnet test
Or via Visual Studio Test Explorer.
Contributing
Contributions are welcome! Please submit issues or pull requests via GitHub.
License
See LICENSE for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 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. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.2.0 | 136 | 10/22/2025 |
| 3.1.0 | 126 | 10/22/2025 |
| 3.0.0 | 277 | 9/17/2025 |
| 1.0.0-CI-20190613-034405 | 514 | 6/13/2019 |
| 1.0.0-CI-20190612-091252 | 474 | 6/12/2019 |
| 1.0.0-CI-20190606-050637 | 521 | 6/6/2019 |
| 1.0.0-CI-20190604-024920 | 501 | 6/4/2019 |