Skip to content

Commit

Permalink
docs(readme): Added C# Usage
Browse files Browse the repository at this point in the history
Add a section about C# usage
  • Loading branch information
vycdev authored Nov 19, 2024
1 parent 6a25a9c commit 45a3692
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A handpicked list of __30242__ unique color names from
| <a href="#usage-">Usage</a>
| <a href="#cdn-">CDN</a>
| <a href="#api-">Public Rest API</a>
| <a href="#usage-js-">Usage JS/Java/Kotlin</a>
| <a href="#usage-js-">Usage JS/Java/Kotlin/C#</a>
| <a href="#sources-">Name Sources</a>
| <a href="#latest-color-names-">Latest Color Names</a>
| <a href="#costs--sponsors">Sponsors</a>
Expand Down Expand Up @@ -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 📇
Expand Down

0 comments on commit 45a3692

Please sign in to comment.