ToolBX.ColorFull 3.0.0

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

ColorFull

ColorFull

A lightweight re-implementation of the color struct.

Why?

The color struct from .NET's System.Drawing is rather heavy when you really just want a container for red, green, blue and alpha values. This library aims to change that by providing easier to use methods and clearer names.

Game engines often re-implement this struct in their own way and this small package is meant to unify these implementations under a simpler type.

Getting started

You can use it the same way as System.Drawing.Color.

public void SomeShadyMethod()
{
    //Returns a color with red, green and blue values. Alpha is implicitly maxed out (255) by default
    var color1 = new Color(255, 255, 125);

    //Alpha is specified in this case 
    var color2 = new Color(68, 125, 200, 45);

    //You can also just use the initializer if you're one of those people who hate constructors. Omitting alpha also initializes it to 255 by default
    var color3 = new Color
    {
        Red = 250,
        Green = 128,
        Blue = 114
    };

    //Or you can also just specify it as well
    var color4 = new Color
    {
        Red = 250,
        Green = 128,
        Blue = 114,
        Alpha = 150
    };

    //Or if you really just want a red color with nothing else
    var color5 = new Color { Red = 255 };

    //If you liked color3 but wanted to adjust its blue value
    var color6 = color3 with { Blue = 189 };
}

Conversions

  • ToHtml : Converts your Color to an hexadecimal color code for use in HTML. Ex : color.ToHtml();
  • FromHtml : Takes an hexadecimal and converts it to an RGBA Color struct. Ex : Color.FromHtml("#FF5733");
  • Also contains an explicit convertor for ConsoleColor. Ex : var newColor = (ConsoleColor)color;

Compatibility with System.Drawing.Color

You can actually use it instead of System.Drawing.Color since it has an implicit conversion operator.

What that means is that whenever you use ColorFull.Color in a method that asks for System.Drawing.Color, .NET will automatically convert that ColorFull.Color to a System.Drawing.Color under the hood.

I wouldn't abuse it but it's there if you need it.

Did you seriously create a whole package just for a measly little struct?!

Yeah, I did. It might grow beyond that and include more eventually. Or not.

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 was computed.  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.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ToolBX.ColorFull:

Package Downloads
ToolBX.DML.NET

.NET implementation of the Dialog Markup Language.

ToolBX.MisterTerminal

A high level library to easily and cleanly build smarter console applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 1,746 9/26/2024
3.0.0-beta1 133 9/23/2024
2.2.1 852 1/13/2024
2.2.0-beta1 156 1/7/2024
2.0.3 280 6/19/2023
2.0.2 359 4/27/2023
2.0.1 366 12/3/2022
2.0.0 462 11/10/2022
2.0.0-beta2 188 10/3/2022
2.0.0-beta1 202 9/21/2022
1.0.5 498 9/21/2022
1.0.5-beta1 203 8/1/2022
1.0.4 500 7/17/2022
1.0.2 471 6/27/2022
1.0.1 756 5/9/2022
1.0.0 598 1/14/2022