From 8ac14fd82ad5ae51b8479c58e1c6a264b876beca Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 16 Feb 2016 19:25:05 +0100 Subject: [PATCH] Make Color immutable. --- src/Perspex.SceneGraph/Media/Color.cs | 45 ++++++++++++--------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/Perspex.SceneGraph/Media/Color.cs b/src/Perspex.SceneGraph/Media/Color.cs index dbc5a108ac..a7b9ec9016 100644 --- a/src/Perspex.SceneGraph/Media/Color.cs +++ b/src/Perspex.SceneGraph/Media/Color.cs @@ -16,22 +16,30 @@ namespace Perspex.Media /// /// Gets or sets the Alpha component of the color. /// - public byte A { get; set; } + public byte A { get; } /// /// Gets or sets the Red component of the color. /// - public byte R { get; set; } + public byte R { get; } /// /// Gets or sets the Green component of the color. /// - public byte G { get; set; } + public byte G { get; } /// /// Gets or sets the Blue component of the color. /// - public byte B { get; set; } + public byte B { get; } + + public Color(byte a, byte r, byte g, byte b) + { + A = a; + R = r; + G = g; + B = b; + } /// /// Creates a from alpha, red, green and blue components. @@ -43,13 +51,7 @@ namespace Perspex.Media /// The color. public static Color FromArgb(byte a, byte r, byte g, byte b) { - return new Color - { - A = a, - R = r, - G = g, - B = b, - }; + return new Color(a, r, g, b); } /// @@ -61,13 +63,7 @@ namespace Perspex.Media /// The color. public static Color FromRgb(byte r, byte g, byte b) { - return new Color - { - A = 0xff, - R = r, - G = g, - B = b, - }; + return new Color(0xff, r, g, b); } /// @@ -77,13 +73,12 @@ namespace Perspex.Media /// The color. public static Color FromUInt32(uint value) { - return new Color - { - A = (byte)((value >> 24) & 0xff), - R = (byte)((value >> 16) & 0xff), - G = (byte)((value >> 8) & 0xff), - B = (byte)(value & 0xff), - }; + return new Color( + (byte)((value >> 24) & 0xff), + (byte)((value >> 16) & 0xff), + (byte)((value >> 8) & 0xff), + (byte)(value & 0xff) + ); } ///