pkNX/pkNX.Structures/Converters/DropTableConverter.cs
JelleInfinity 4167762c44
Some bug fixes (#276)
* Replace all uses of ModelID

* Prep work to add PokeMisc data
2022-10-05 17:01:34 +01:00

41 lines
1.2 KiB
C#

using System;
using System.ComponentModel;
using System.Globalization;
namespace pkNX.Structures;
public class DropTableConverter : TypeConverter
{
public static ulong[] DropTableHashes = Array.Empty<ulong>();
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string s)
{
return ulong.Parse(s);
}
return base.ConvertFrom(context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string) && value is ulong i)
return i.ToString();
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(DropTableHashes);
}
}