2019-06-02 02:12:41 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-03-19 04:34:21 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
2016-07-09 22:34:38 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
2019-06-02 02:12:41 +00:00
|
|
|
|
/// Key Value pair for a displayed <see cref="T:System.String" /> and underlying <see cref="T:System.Int32" /> value.
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// </summary>
|
2019-06-02 02:12:41 +00:00
|
|
|
|
public readonly struct ComboItem : IEquatable<int>
|
2016-07-09 22:34:38 +00:00
|
|
|
|
{
|
2019-10-27 06:18:25 +00:00
|
|
|
|
public readonly string Text;
|
|
|
|
|
public readonly int Value;
|
|
|
|
|
|
2019-06-02 02:12:41 +00:00
|
|
|
|
public ComboItem(string text, int value)
|
|
|
|
|
{
|
|
|
|
|
Text = text;
|
|
|
|
|
Value = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Equals(ComboItem other) => Value == other.Value && string.Equals(Text, other.Text);
|
|
|
|
|
public bool Equals(int other) => Value == other;
|
2019-10-27 06:18:25 +00:00
|
|
|
|
public override bool Equals(object obj) => obj is ComboItem other && Equals(other);
|
|
|
|
|
public override int GetHashCode() => Value;
|
2019-10-08 01:40:09 +00:00
|
|
|
|
public static bool operator ==(ComboItem left, ComboItem right) => left.Equals(right);
|
|
|
|
|
public static bool operator !=(ComboItem left, ComboItem right) => !(left == right);
|
2016-07-09 22:34:38 +00:00
|
|
|
|
}
|
2019-03-19 04:34:21 +00:00
|
|
|
|
|
|
|
|
|
public static class ComboItemExtensions
|
|
|
|
|
{
|
|
|
|
|
public static string[] GetArray(this IReadOnlyList<ComboItem> list)
|
|
|
|
|
{
|
|
|
|
|
var max = list[list.Count - 1].Value;
|
|
|
|
|
return GetArray(list, max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string[] GetArray(this IEnumerable<ComboItem> list, int max)
|
|
|
|
|
{
|
|
|
|
|
var arr = new string[max + 1];
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
arr[item.Value] = item.Text;
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-09 22:34:38 +00:00
|
|
|
|
}
|