From 45a3692adee163be7bcfb6d1247fc8b9ecc47b25 Mon Sep 17 00:00:00 2001 From: vycdev Date: Tue, 19 Nov 2024 23:45:01 +0200 Subject: [PATCH] docs(readme): Added C# Usage Add a section about C# usage --- README.md | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc24d54f..996f84c0 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ A handpicked list of __30242__ unique color names from | Usage | CDN | Public Rest API - | Usage JS/Java/Kotlin + | Usage JS/Java/Kotlin/C# | Name Sources | Latest Color Names | Sponsors @@ -233,6 +233,43 @@ val fromRGB = colorNames.getName(224, 224, 255) // "Stoic White" val fromColor = colorNames.getName(Color(255, 219, 240)) // "Silky Pink" ``` +### Usage C# ⌨ + +C# usage is maintained through this library: +[vycdev/ColorNamesSharp](https://github.com/vycdev/ColorNamesSharp) +Additional info can be found there, but basic usage is outlined below: + +You can download and install the [nuget package from here.](https://www.nuget.org/packages/ColorNamesSharp) + +#### Creating the instance + +```csharp +ColorNames colorNames = new ColorNamesBuilder() + .Add("Best Blue", "#3299fe") // Add your own custom colors + .LoadDefault() // Load the default color list + .AddFromCsv("path/to/your/colorlist.csv") // Add a custom color list from a csv file + .Build(); // Get a new ColorNames instance that includes all the colors you've added +``` + +#### Getting a fitting color name + +```csharp +NamedColor customNamedColor = new("Custom Named Color", 50, 153, 254); + +// You can directly get the name of the color as a string +string colorNameFromHex = colorNames.FindClosestColorName("#facfea"); // Classic Rose +string colorNameFromRgb = colorNames.FindClosestColorName(224, 224, 255); // Stoic White +string colorNameFromNamedColor = colorNames.FindClosestColorName(customNamedColor); // Best Blue + +// Or similarly you can get the NamedColor object +NamedColor namedColorFromHex = colorNames.FindClosestColorName("#facfea"); // Classic Rose +NamedColor namedColorFromRgb = colorNames.FindClosestColorName(224, 224, 255); // Stoic White +NamedColor namedColorFromNamedColor = colorNames.FindClosestColorName(customNamedColor); // Best Blue + +// Or a random color +NamedColor randomColor = colorNames.GetRandomNamedColor(); +``` + ## Sources 🗒 ### Sources: Names 📇