Restructure and update example image

This commit is contained in:
Patrik Svensson
2020-08-25 11:19:58 +02:00
parent 695327ec72
commit c111c7d463
20 changed files with 3 additions and 2 deletions

View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
namespace Generator.Models
{
public sealed class Color
{
public int Number { get; set; }
public string Hex { get; set; }
public string Name { get; set; }
public Rgb Rgb { get; set; }
public int R => Rgb.R;
public int G => Rgb.G;
public int B => Rgb.B;
public static IEnumerable<Color> Parse(string json)
{
var source = JsonConvert.DeserializeObject<List<Color>>(json);
var check = new Dictionary<string, Color>(StringComparer.OrdinalIgnoreCase);
foreach (var color in source.OrderBy(c => c.Number))
{
if (!check.ContainsKey(color.Name))
{
check.Add(color.Name, color);
}
else
{
var newName = (string)null;
for (int i = 1; i < 100; i++)
{
if (!check.ContainsKey($"{color.Name}_{i}"))
{
newName = $"{color.Name}_{i}";
break;
}
}
if (newName == null)
{
throw new InvalidOperationException("Impossible!");
}
check.Add(newName, color);
color.Name = newName;
}
}
return source;
}
}
public sealed class Rgb
{
public int R { get; set; }
public int G { get; set; }
public int B { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Generator.Models
{
public sealed class ColorModel
{
public List<Color> Colors { get; set; }
public ColorModel(IEnumerable<Color> colors)
{
Colors = new List<Color>(colors);
}
}
}

View File

@ -0,0 +1,6 @@
namespace Generator.Models
{
public sealed class Palette
{
}
}