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
byteThe byte that represents the red color.
g
byteThe byte that represents the green color.
b
byteThe 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
intThe value that represents the red color. Must be within 0~255.
g
intThe value that represents the green color. Must be within 0~255.
b
intThe 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
floatThe value that represents the red color. Must be within 0~1.
g
floatThe value that represents the green color. Must be within 0~1.
b
floatThe 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
uintThe 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
DarkBlue
Gets the dark blue color value.
public static readonly Color DarkBlue
Field Value
DarkGreen
Gets the dark green color value.
public static readonly Color DarkGreen
Field Value
DarkGrey
Gets the dark grey color value.
public static readonly Color DarkGrey
Field Value
DarkMagenta
Gets the dark magenta color value.
public static readonly Color DarkMagenta
Field Value
DarkOrange
Gets the dark orange color value.
public static readonly Color DarkOrange
Field Value
DarkPurple
Gets the dark purple color value.
public static readonly Color DarkPurple
Field Value
DarkRed
Gets the dark red color value.
public static readonly Color DarkRed
Field Value
DarkTeal
Gets the dark teal color value.
public static readonly Color DarkTeal
Field Value
DarkerGrey
Gets the darker grey color value.
public static readonly Color DarkerGrey
Field Value
Default
Gets the default user color value.
public static readonly Color Default
Field Value
Gold
Gets the gold color value.
public static readonly Color Gold
Field Value
Green
Gets the green color value.
public static readonly Color Green
Field Value
LightGrey
Gets the light grey color value.
public static readonly Color LightGrey
Field Value
LightOrange
Gets the light orange color value.
public static readonly Color LightOrange
Field Value
LighterGrey
Gets the lighter grey color value.
public static readonly Color LighterGrey
Field Value
Magenta
Gets the magenta color value.
public static readonly Color Magenta
Field Value
MaxDecimalValue
Gets the max decimal value of color.
public const uint MaxDecimalValue = 16777215
Field Value
Orange
Gets the orange color value.
public static readonly Color Orange
Field Value
Purple
Gets the purple color value.
public static readonly Color Purple
Field Value
Red
Gets the red color value.
public static readonly Color Red
Field Value
Teal
Gets the teal color value.
public static readonly Color Teal
Field Value
Properties
B
Gets the blue component for this color.
public byte B { get; }
Property Value
G
Gets the green component for this color.
public byte G { get; }
Property Value
R
Gets the red component for this color.
public byte R { get; }
Property Value
RawValue
Gets the encoded value for this color.
public readonly uint RawValue { get; }
Property Value
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
objectThe 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
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
stringString to be parsed to a color
color
ColorWhen this method returns true, contains a Color that represents the parsed string.
colorType
ColorTypeColor 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
Returns
explicit operator Color(Color)
public static explicit operator Color(Color color)
Parameters
color
Color
Returns
implicit operator Color(Color)
public static implicit operator Color(Color color)
Parameters
color
Color
Returns
implicit operator uint(Color)
public static implicit operator uint(Color color)
Parameters
color
Color
Returns
implicit operator Color(uint)
public static implicit operator Color(uint rawValue)
Parameters
rawValue
uint
Returns
operator !=(Color, Color)
public static bool operator !=(Color lhs, Color rhs)