Table of Contents

Struct Color

Namespace
Discord
Assembly
Discord.Net.Core.dll

Represents a color used in Discord.

public struct Color
Inherited Members

Constructors

Color(byte, byte, byte)

Initializes a Color struct with the given RGB bytes.

public Color(byte r, byte g, byte b)

Parameters

r byte

The byte that represents the red color.

g byte

The byte that represents the green color.

b byte

The byte that represents the blue color.

Examples

The following will create a color that has a value of #607D8B.

Color darkGrey = new Color((byte)0b_01100000, (byte)0b_01111101, (byte)0b_10001011);

Exceptions

ArgumentException

Value exceeds MaxDecimalValue.

Color(int, int, int)

Initializes a Color struct with the given RGB value.

public Color(int r, int g, int b)

Parameters

r int

The value that represents the red color. Must be within 0~255.

g int

The value that represents the green color. Must be within 0~255.

b int

The value that represents the blue color. Must be within 0~255.

Examples

The following will create a color that has a value of #607D8B.

Color darkGrey = new Color(96, 125, 139);

Exceptions

ArgumentOutOfRangeException

The argument value is not between 0 to 255.

Color(float, float, float)

Initializes a Color struct with the given RGB float value.

public Color(float r, float g, float b)

Parameters

r float

The value that represents the red color. Must be within 0~1.

g float

The value that represents the green color. Must be within 0~1.

b float

The value that represents the blue color. Must be within 0~1.

Examples

The following will create a color that has a value of #607c8c.

Color darkGrey = new Color(0.38f, 0.49f, 0.55f);

Exceptions

ArgumentOutOfRangeException

The argument value is not between 0 to 1.

Color(uint)

Initializes a Color struct with the given raw value.

public Color(uint rawValue)

Parameters

rawValue uint

The raw value of the color (e.g. 0x607D8B).

Examples

The following will create a color that has a hex value of #607D8B.

Color darkGrey = new Color(0x607D8B);

Exceptions

ArgumentException

Value exceeds MaxDecimalValue.

Fields

Blue

Gets the blue color value.

public static readonly Color Blue

Field Value

Color

A color struct with the hex value of 3498DB.

DarkBlue

Gets the dark blue color value.

public static readonly Color DarkBlue

Field Value

Color

A color struct with the hex value of 206694.

DarkGreen

Gets the dark green color value.

public static readonly Color DarkGreen

Field Value

Color

A color struct with the hex value of 1F8B4C.

DarkGrey

Gets the dark grey color value.

public static readonly Color DarkGrey

Field Value

Color

A color struct with the hex value of 607D8B.

DarkMagenta

Gets the dark magenta color value.

public static readonly Color DarkMagenta

Field Value

Color

A color struct with the hex value of AD1457.

DarkOrange

Gets the dark orange color value.

public static readonly Color DarkOrange

Field Value

Color

A color struct with the hex value of A84300.

DarkPurple

Gets the dark purple color value.

public static readonly Color DarkPurple

Field Value

Color

A color struct with the hex value of 71368A.

DarkRed

Gets the dark red color value.

public static readonly Color DarkRed

Field Value

Color

A color struct with the hex value of 992D22.

DarkTeal

Gets the dark teal color value.

public static readonly Color DarkTeal

Field Value

Color

A color struct with the hex value of 11806A.

DarkerGrey

Gets the darker grey color value.

public static readonly Color DarkerGrey

Field Value

Color

A color struct with the hex value of 546E7A.

Default

Gets the default user color value.

public static readonly Color Default

Field Value

Color

Gold

Gets the gold color value.

public static readonly Color Gold

Field Value

Color

A color struct with the hex value of F1C40F.

Green

Gets the green color value.

public static readonly Color Green

Field Value

Color

A color struct with the hex value of 2ECC71.

LightGrey

Gets the light grey color value.

public static readonly Color LightGrey

Field Value

Color

A color struct with the hex value of 979C9F.

LightOrange

Gets the light orange color value.

public static readonly Color LightOrange

Field Value

Color

A color struct with the hex value of C27C0E.

LighterGrey

Gets the lighter grey color value.

public static readonly Color LighterGrey

Field Value

Color

A color struct with the hex value of 95A5A6.

Magenta

Gets the magenta color value.

public static readonly Color Magenta

Field Value

Color

A color struct with the hex value of E91E63.

MaxDecimalValue

Gets the max decimal value of color.

public const uint MaxDecimalValue = 16777215

Field Value

uint

Orange

Gets the orange color value.

public static readonly Color Orange

Field Value

Color

A color struct with the hex value of E67E22.

Purple

Gets the purple color value.

public static readonly Color Purple

Field Value

Color

A color struct with the hex value of 9B59B6.

Red

Gets the red color value.

public static readonly Color Red

Field Value

Color

A color struct with the hex value of E74C3C.

Teal

Gets the teal color value.

public static readonly Color Teal

Field Value

Color

A color struct with the hex value of 1ABC9C.

Properties

B

Gets the blue component for this color.

public byte B { get; }

Property Value

byte

G

Gets the green component for this color.

public byte G { get; }

Property Value

byte

R

Gets the red component for this color.

public byte R { get; }

Property Value

byte

RawValue

Gets the encoded value for this color.

public readonly uint RawValue { get; }

Property Value

uint

Remarks

This value is encoded as an unsigned integer value. The most-significant 8 bits contain the red value, the middle 8 bits contain the green value, and the least-significant 8 bits contain the blue value.

Methods

Equals(object)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Parse(string, ColorType)

Converts the string representation of a color to a Color object.

public static Color Parse(string rawValue, ColorType colorType = ColorType.CssHexColor)

Parameters

rawValue string

String to be parsed to a color

colorType ColorType

Color format of the string

Returns

Color

A Color object with a color value parsed from a string

Exceptions

ArgumentOutOfRangeException

The argument is not a number or of incorrect length

ToString()

Gets the hexadecimal representation of the color (e.g. #000ccc).

public override string ToString()

Returns

string

A hexadecimal string of the color.

TryParse(string, out Color, ColorType)

Converts the string representation of a color to a Color object. The return value indicates whether the conversion succeeded.

public static bool TryParse(string rawValue, out Color color, ColorType colorType = ColorType.CssHexColor)

Parameters

rawValue string

String to be parsed to a color

color Color

When this method returns true, contains a Color that represents the parsed string.

colorType ColorType

Color format of the string

Returns

bool

true if the conversion succeeded; false otherwise.

Operators

operator ==(Color, Color)

public static bool operator ==(Color lhs, Color rhs)

Parameters

lhs Color
rhs Color

Returns

bool

explicit operator Color(Color)

public static explicit operator Color(Color color)

Parameters

color Color

Returns

Color

implicit operator Color(Color)

public static implicit operator Color(Color color)

Parameters

color Color

Returns

Color

implicit operator uint(Color)

public static implicit operator uint(Color color)

Parameters

color Color

Returns

uint

implicit operator Color(uint)

public static implicit operator Color(uint rawValue)

Parameters

rawValue uint

Returns

Color

operator !=(Color, Color)

public static bool operator !=(Color lhs, Color rhs)

Parameters

lhs Color
rhs Color

Returns

bool