NanoXLSX.Core 3.0.0-rc.4
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 © 2025
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;
9using System.Drawing;
11using NanoXLSX.Utils;
12
13namespace NanoXLSX.Colors
14{
15
19 public class SrgbColor : ITypedColor<string>
20 {
21 #region constants
25 public const string DefaultSrgbColor = "FF000000";
26 #endregion
27
28 private string colorValue;
29
34 public string ColorValue
35 {
36 get => colorValue;
37 set
38 {
39 Validators.ValidateGenericColor(value, false);
40 if (value.Length == 6)
41 {
42 colorValue = "FF" + ParserUtils.ToUpper(value);
43 }
44 else
45 {
46 colorValue = ParserUtils.ToUpper(value);
47 }
48 }
49 }
50
54 public string StringValue => colorValue;
55
59 public SrgbColor()
60 {
61 }
62
67 public SrgbColor(string rgb) : this()
68 {
69 ColorValue = rgb;
70 }
71
77 public override bool Equals(object obj)
78 {
79 return obj is SrgbColor color &&
80 ColorValue == color.ColorValue;
81 }
82
87 public override int GetHashCode()
88 {
89 return 800285905 + EqualityComparer<string>.Default.GetHashCode(ColorValue);
90 }
91 }
92}
const string DefaultSrgbColor
Default color value (opaque black: #000000).
Definition SrgbColor.cs:25
string StringValue
Gets the string value of the color. The value is identical to ColorValue and defined as interface imp...
Definition SrgbColor.cs:54
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:35
SrgbColor()
Default constructor.
Definition SrgbColor.cs:59
override int GetHashCode()
Gets the hash code of the instance.
Definition SrgbColor.cs:87
override bool Equals(object obj)
Determines whether the specified object is equal to the current object.
Definition SrgbColor.cs:77
SrgbColor(string rgb)
Constructor with parameters.
Definition SrgbColor.cs:67
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