OpenCode 3.2.0

Prefix Reserved
dotnet add package OpenCode --version 3.2.0
                    
NuGet\Install-Package OpenCode -Version 3.2.0
                    
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="OpenCode" Version="3.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenCode" Version="3.2.0" />
                    
Directory.Packages.props
<PackageReference Include="OpenCode" />
                    
Project file
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 OpenCode --version 3.2.0
                    
#r "nuget: OpenCode, 3.2.0"
                    
#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 OpenCode@3.2.0
                    
#: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=OpenCode&version=3.2.0
                    
Install as a Cake Addin
#tool nuget:?package=OpenCode&version=3.2.0
                    
Install as a Cake Tool

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 — returns null for null/empty/whitespace input.
  • OrDefault — returns a specified default value when input is null/empty/whitespace.
  • SafeTrim — trims input safely; returns empty string if input is null.
  • 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 to snake_case or kebab-case.
  • ToSlug — produces a URL-safe slug (diacritics removed, spaces → dashes).
  • Mask — mask middle characters, leaving configurable head/tail visible.
  • FormatWith — culture-invariant wrapper for string.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 (uses G29 to preserve significance).
  • IsDecimal, IsInteger — validate numeric strings.
  • ToOrdinal — converts numeric string to English ordinal (e.g., 11st).

Boolean Helpers

  • ParseToBool — accepts true/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

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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