NanoXLSX.Core 3.0.0-rc.3
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;
10using NanoXLSX.Utils;
11
12namespace NanoXLSX.Themes
13{
14
18 public class SrgbColor : ITypedColor<string>
19 {
20 private string colorValue;
21
25 public string ColorValue
26 {
27 get => colorValue;
28 set
29 {
30 Validators.ValidateColor(value, false);
31 colorValue = ParserUtils.ToUpper(value);
32 }
33 }
34
38 public string StringValue => colorValue;
39
43 public SrgbColor()
44 {
45 }
46
51 public SrgbColor(string rgb) : this()
52 {
53 this.ColorValue = rgb;
54 }
55
60 public string ToArgbColor()
61 {
62 // Is already validated
63 return "FF" + colorValue;
64 }
65
71 public override bool Equals(object obj)
72 {
73 return obj is SrgbColor color &&
74 ColorValue == color.ColorValue;
75 }
76
81 public override int GetHashCode()
82 {
83 return 800285905 + EqualityComparer<string>.Default.GetHashCode(ColorValue);
84 }
85 }
86}
string ColorValue
Gets or sets the sRGB value (Hex code of RGB). If set, the value will be cast to upper case.
Definition SrgbColor.cs:26
override int GetHashCode()
Gets the hash code of the instance.
Definition SrgbColor.cs:81
override bool Equals(object obj)
Determines whether the specified object is equal to the current object.
Definition SrgbColor.cs:71
string StringValue
Gets the string value of the color. The value is identical to ColorValue and defined as interface imp...
Definition SrgbColor.cs:38
SrgbColor(string rgb)
Constructor with parameters.
Definition SrgbColor.cs:51
SrgbColor()
Default constructor.
Definition SrgbColor.cs:43
string ToArgbColor()
Converts the sRGB value to an ARGB value.
Definition SrgbColor.cs:60
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 ValidateColor(string hexCode, bool useAlpha, bool allowEmpty=false)
Validates the passed string, whether it is a valid RGB or ARGB value that can be used for Fills or Fo...
Definition Validators.cs:25