NanoXLSX.Core 3.0.0-rc.5
Loading...
Searching...
No Matches
SrgbColor.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2026
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
8using System.Collections.Generic;
10using NanoXLSX.Utils;
11
12namespace NanoXLSX.Colors
13{
14
18 public class SrgbColor : ITypedColor<string>
19 {
20 #region constants
24 public const string DefaultSrgbColor = "FF000000";
25 #endregion
26
27 private string colorValue;
28
33 public string ColorValue
34 {
35 get => colorValue;
36 set
37 {
38 Validators.ValidateGenericColor(value, false);
39 if (value.Length == 6)
40 {
41 colorValue = "FF" + ParserUtils.ToUpper(value);
42 }
43 else
44 {
45 colorValue = ParserUtils.ToUpper(value);
46 }
47 }
48 }
49
53 public string StringValue => colorValue;
54
58 public SrgbColor()
59 {
60 }
61
66 public SrgbColor(string rgb) : this()
67 {
68 ColorValue = rgb;
69 }
70
76 public override bool Equals(object obj)
77 {
78 return obj is SrgbColor color &&
79 ColorValue == color.ColorValue;
80 }
81
86 public override int GetHashCode()
87 {
88 return 800285905 + EqualityComparer<string>.Default.GetHashCode(ColorValue);
89 }
90 }
91}
const string DefaultSrgbColor
Default color value (opaque black: #000000).
Definition SrgbColor.cs:24
string StringValue
Gets the string value of the color. The value is identical to ColorValue and defined as interface imp...
Definition SrgbColor.cs:53
string ColorValue
Gets or sets the sRGB value (Hex code of RGB/ARGB). If set, the value will be cast to upper case....
Definition SrgbColor.cs:34
SrgbColor()
Default constructor.
Definition SrgbColor.cs:58
override int GetHashCode()
Gets the hash code of the instance.
Definition SrgbColor.cs:86
override bool Equals(object obj)
Determines whether the specified object is equal to the current object.
Definition SrgbColor.cs:76
SrgbColor(string rgb)
Constructor with parameters.
Definition SrgbColor.cs:66
Class providing static methods to parse string values to specific types or to print object as languag...
static string ToUpper(string input)
Transforms a string to upper case with null check and invariant culture.
Class providing general validator methods.
Definition Validators.cs:11
static void ValidateGenericColor(string hexCode, bool allowEmpty=false)
Validates the passed string, whether it is a valid RGB or ARGB value that can be used for Fills,...
Definition Validators.cs:19