-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSvgColor.cs
More file actions
46 lines (37 loc) · 2.04 KB
/
SvgColor.cs
File metadata and controls
46 lines (37 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
namespace RT.Coordinates;
/// <summary>Describes an SVG color with optional opacity information.</summary>
public struct SvgColor(string color = null, string opacity = null) : IEquatable<SvgColor>
{
/// <summary>Determines the SVG color, or <c>null</c> to use a default color.</summary>
public string SvgFillColor { get; private set; } = color;
/// <summary>Determines the SVG fill opacity, or <c>null</c> to omit the attribute.</summary>
public string SvgFillOpacity { get; private set; } = opacity;
/// <inheritdoc/>
public override readonly bool Equals(object obj) => obj is SvgColor other && SvgFillColor == other.SvgFillColor && SvgFillOpacity == other.SvgFillOpacity;
/// <inheritdoc/>
public readonly bool Equals(SvgColor other) => SvgFillColor == other.SvgFillColor && SvgFillOpacity == other.SvgFillOpacity;
/// <inheritdoc/>
public override readonly int GetHashCode()
{
var hashCode = 1413938657;
hashCode = unchecked(hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(SvgFillColor));
hashCode = unchecked(hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(SvgFillOpacity));
return hashCode;
}
/// <summary>Deconstructor.</summary>
public readonly void Deconstruct(out string color, out string opacity)
{
color = SvgFillColor;
opacity = SvgFillOpacity;
}
/// <inheritdoc/>
public override readonly string ToString() => $"{SvgFillColor}{(SvgFillOpacity == null ? "" : "/")}{SvgFillOpacity}";
/// <summary>Implicitly converts a string (containing an SVG color) to an opaque <see cref="SvgColor"/>.</summary>
public static implicit operator SvgColor(string color) => new(color: color);
/// <summary>Equality operator.</summary>
public static bool operator ==(SvgColor left, SvgColor right) => left.Equals(right);
/// <summary>Inequality operator.</summary>
public static bool operator !=(SvgColor left, SvgColor right) => !left.Equals(right);
}