Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrand Le Roy <beleroy@microsoft.com>2018-09-21 21:48:01 +0300
committerBertrand Le Roy <beleroy@microsoft.com>2018-09-21 21:48:01 +0300
commit51e755eded6517f1f2423b02ebeb0d3bfa1d7809 (patch)
tree44e01f931202d21ca1ddf2d380fe27c7775f1559 /Xamarin.PropertyEditing
parent3a99673a4082de39bedc5018857d5f52fea66e1a (diff)
Add `CommonColor.ToArgbHex`, throw in some additional tests for good measure.
Diffstat (limited to 'Xamarin.PropertyEditing')
-rw-r--r--Xamarin.PropertyEditing/Drawing/CommonColor.cs16
1 files changed, 6 insertions, 10 deletions
diff --git a/Xamarin.PropertyEditing/Drawing/CommonColor.cs b/Xamarin.PropertyEditing/Drawing/CommonColor.cs
index 915dddd..485c2bf 100644
--- a/Xamarin.PropertyEditing/Drawing/CommonColor.cs
+++ b/Xamarin.PropertyEditing/Drawing/CommonColor.cs
@@ -366,10 +366,9 @@ namespace Xamarin.PropertyEditing.Drawing
return delta == 0 ? highest : (component - lowest) * 255 / delta;
}
- public string ToRgbaHex ()
- {
- return $"#{R:X2}{G:X2}{B:X2}{A:X2}";
- }
+ public string ToRgbaHex () => $"#{R:X2}{G:X2}{B:X2}{A:X2}";
+
+ public string ToArgbHex () => (A == 255) ? $"#{R:X2}{G:X2}{B:X2}" : $"#{A:X2}{R:X2}{G:X2}{B:X2}";
public static bool TryParseArgbHex (string value, out CommonColor color)
{
@@ -377,8 +376,8 @@ namespace Xamarin.PropertyEditing.Drawing
var hex = value.Substring (1);
switch (hex.Length) {
case 3:
- hex = $"{hex[0]}{hex[0]}{hex[1]}{hex[1]}{hex[2]}{hex[2]}";
- goto case 6;
+ hex = $"FF{hex[0]}{hex[0]}{hex[1]}{hex[1]}{hex[2]}{hex[2]}";
+ goto case 8;
case 6:
hex = "FF" + hex;
goto case 8;
@@ -576,9 +575,6 @@ namespace Xamarin.PropertyEditing.Drawing
return hashCode;
}
- public override string ToString ()
- {
- return (A == 255) ? $"#{R:X2}{G:X2}{B:X2}" : $"#{A:X2}{R:X2}{G:X2}{B:X2}";
- }
+ public override string ToString () => ToArgbHex ();
}
}