mirror of
https://github.com/kwsch/pkNX.git
synced 2026-09-08 02:25:15 -05:00
File scoped namespaces for all lib projects netstandard2.0 => net6; now uniform. bye netframework!
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
|
|
namespace pkNX.Structures;
|
|
|
|
public class ItemConverter : TypeConverter
|
|
{
|
|
public static string[] ItemNames = Array.Empty<string>();
|
|
|
|
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 Array.IndexOf(ItemNames, 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 int i)
|
|
return ItemNames[i];
|
|
|
|
return base.ConvertTo(context, culture, value, destinationType);
|
|
}
|
|
|
|
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
|
|
|
|
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
|
|
{
|
|
return new StandardValuesCollection(ItemNames);
|
|
}
|
|
}
|