aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/Colors.cs
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2017-11-01 11:30:21 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2017-11-01 11:30:21 +0100
commit516dfa48adbcbec0b2dc55dd33e1f96b89e2672a (patch)
treef7324defc7fe77a4e5acf141b36431808ce221f0 /src/Colors.cs
parent96e1c971f30b8141c5245d341a26fc92b972cfe1 (diff)
Use Dictionary to store color names
Diffstat (limited to 'src/Colors.cs')
-rw-r--r--src/Colors.cs24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/Colors.cs b/src/Colors.cs
index 3f200829..7317516d 100644
--- a/src/Colors.cs
+++ b/src/Colors.cs
@@ -59,11 +59,11 @@ namespace Crow
G = _G;
B = _B;
Name = _name;
- ColorDic.Add(this);
+ ColorDic.Add(_name,this);
}
#endregion
- public static List<Color> ColorDic = new List<Color>();
+ public static Dictionary<string, Color> ColorDic = new Dictionary<string, Color>();
internal string Name;
@@ -88,11 +88,9 @@ namespace Crow
if (c.Length == 1)
{
- foreach (Color cr in ColorDic)
- {
- if (string.Equals(cr.Name,s,StringComparison.Ordinal))
- return cr;
- }
+ if (ColorDic.ContainsKey (s))
+ return ColorDic[s];
+ throw new Exception ("Unknown color name: " + s);
}
return new Color(
double.Parse(c[0]),
@@ -1126,15 +1124,9 @@ namespace Crow
{
if (!string.IsNullOrEmpty(Name))
return Name;
-
- foreach (Color cr in ColorDic)
- {
- if (cr == this)
- {
- Name = cr.Name;
- return cr.Name;
- }
- }
+ Color tc = this;
+ if (ColorDic.ContainsValue (this))
+ return ColorDic.FirstOrDefault (c => c.Value == tc).Key;
return string.Format("{0},{1},{2},{3}", R, G, B, A);
}