Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions ColorHelper/Color/CMYK.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace ColorHelper
{
public class CMYK : IColor
public readonly record struct CMYK : IColor
{
public byte C { get; set; }
public byte M { get; set; }
public byte Y { get; set; }
public byte K { get; set; }
public byte C { get; }
public byte M { get; }
public byte Y { get; }
public byte K { get; }

public CMYK(byte c, byte m, byte y, byte k)
{
Expand All @@ -15,18 +15,6 @@ public CMYK(byte c, byte m, byte y, byte k)
this.K = k;
}

public override bool Equals(object obj)
{
var result = (CMYK)obj;

return (
result != null &&
this.C == result.C &&
this.M == result.M &&
this.Y == result.Y &&
this.K == result.K);
}

public override string ToString()
{
return $"{this.C}% {this.M}% {this.Y}% {this.K}%";
Expand Down
19 changes: 4 additions & 15 deletions ColorHelper/Color/HEX.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
namespace ColorHelper
{
public class HEX : IColor
public readonly record struct HEX : IColor
{
private string _value;

public string Value
{
get { return _value; }
set { _value = (value.IndexOf('#') == 0) ? value.Substring(1) : value; }
}
public string Value { get; }

public HEX(string value)
{
this.Value = value;
}

public override bool Equals(object obj)
{
return this.Value == (obj as HEX)?.Value;
Value = value.IndexOf('#') == 0 ? value.Substring(1) : value;
}

public override string ToString()
{
return $"{this.Value}";
return Value;
}
}
}
19 changes: 4 additions & 15 deletions ColorHelper/Color/HSL.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ColorHelper
{
public class HSL : IColor
public readonly record struct HSL : IColor
{
public int H { get; set; }
public byte S { get; set; }
public byte L { get; set; }
public int H { get; }
public byte S { get; }
public byte L { get; }

public HSL(int h, byte s, byte l)
{
Expand All @@ -13,17 +13,6 @@ public HSL(int h, byte s, byte l)
this.L = l;
}

public override bool Equals(object obj)
{
var result = (HSL)obj;

return (
result != null &&
this.H == result.H &&
this.S == result.S &&
this.L == result.L);
}

public override string ToString()
{
return $"{this.H}° {this.S}% {this.L}%";
Expand Down
19 changes: 4 additions & 15 deletions ColorHelper/Color/HSV.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ColorHelper
{
public class HSV : IColor
public readonly record struct HSV : IColor
{
public int H { get; set; }
public byte S { get; set; }
public byte V { get; set; }
public int H { get; }
public byte S { get; }
public byte V { get; }

public HSV(int h, byte s, byte v)
{
Expand All @@ -13,17 +13,6 @@ public HSV(int h, byte s, byte v)
this.V = v;
}

public override bool Equals(object obj)
{
var result = (HSV)obj;

return (
result != null &&
this.H == result.H &&
this.S == result.S &&
this.V == result.V);
}

public override string ToString()
{
return $"{this.H}° {this.S}% {this.V}%";
Expand Down
19 changes: 4 additions & 15 deletions ColorHelper/Color/RGB.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ColorHelper
{
public class RGB : IColor
public readonly record struct RGB : IColor
{
public byte R { get; set; }
public byte G { get; set; }
public byte B { get; set; }
public byte R { get; }
public byte G { get; }
public byte B { get; }

public RGB(byte r, byte g, byte b)
{
Expand All @@ -13,17 +13,6 @@ public RGB(byte r, byte g, byte b)
this.B = b;
}

public override bool Equals(object obj)
{
var result = (RGB) obj;

return (
result != null &&
this.R == result.R &&
this.G == result.G &&
this.B == result.B);
}

public override string ToString()
{
return $"rgb({this.R}, {this.G}, {this.B})";
Expand Down
19 changes: 4 additions & 15 deletions ColorHelper/Color/XYZ.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ColorHelper
{
public class XYZ : IColor
public readonly record struct XYZ : IColor
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
public double X { get; }
public double Y { get; }
public double Z { get; }

public XYZ(double x, double y, double z)
{
Expand All @@ -13,17 +13,6 @@ public XYZ(double x, double y, double z)
this.Z = z;
}

public override bool Equals(object obj)
{
var result = (XYZ)obj;

return (
result != null &&
this.X == result.X &&
this.Y == result.Y &&
this.Z == result.Z);
}

public override string ToString()
{
return $"{this.X} {this.Y} {this.Z}";
Expand Down
19 changes: 4 additions & 15 deletions ColorHelper/Color/YIQ.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ColorHelper
{
public class YIQ : IColor
public readonly record struct YIQ : IColor
{
public double Y { get; set; }
public double I { get; set; }
public double Q { get; set; }
public double Y { get; }
public double I { get; }
public double Q { get; }

public YIQ(double y, double i, double q)
{
Expand All @@ -13,17 +13,6 @@ public YIQ(double y, double i, double q)
this.Q = q;
}

public override bool Equals(object obj)
{
var result = (YIQ)obj;

return (
result != null &&
this.Y == result.Y &&
this.I == result.I &&
this.Q == result.Q);
}

public override string ToString()
{
return $"{this.Y} {this.I} {this.Q}";
Expand Down
19 changes: 4 additions & 15 deletions ColorHelper/Color/YUV.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ColorHelper
{
public class YUV : IColor
public readonly record struct YUV : IColor
{
public double Y { get; set; }
public double U { get; set; }
public double V { get; set; }
public double Y { get; }
public double U { get; }
public double V { get; }

public YUV(double y, double u, double v)
{
Expand All @@ -13,17 +13,6 @@ public YUV(double y, double u, double v)
this.V = v;
}

public override bool Equals(object obj)
{
var result = (YUV)obj;

return (
result != null &&
this.Y == result.Y &&
this.U == result.U &&
this.V == result.V);
}

public override string ToString()
{
return $"{this.Y} {this.U} {this.V}";
Expand Down
1 change: 1 addition & 0 deletions ColorHelper/ColorHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Authors>Artyom Gritsuk</Authors>
<RepositoryUrl>https://github.com/iamartyom/ColorHelper</RepositoryUrl>
<PackageProjectUrl>https://github.com/iamartyom/ColorHelper</PackageProjectUrl>
Expand Down