增加StringEnumConverter
This commit is contained in:
@@ -19,7 +19,7 @@ namespace SpineViewer.Exporter.Implementations.ExportArgs
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件名后缀
|
/// 文件名后缀
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TypeConverter(typeof(SFMLImageFileSuffixConverter))]
|
[TypeConverter(typeof(StringEnumConverter)), StringEnumConverter.StandardValues(".png", ".jpg", ".tga", ".bmp")]
|
||||||
[Category("[2] 帧序列参数"), DisplayName("文件名后缀"), Description("帧文件的后缀,同时决定帧图像格式")]
|
[Category("[2] 帧序列参数"), DisplayName("文件名后缀"), Description("帧文件的后缀,同时决定帧图像格式")]
|
||||||
public string FileSuffix { get; set; } = ".png";
|
public string FileSuffix { get; set; } = ".png";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,20 +10,6 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace SpineViewer.Exporter
|
namespace SpineViewer.Exporter
|
||||||
{
|
{
|
||||||
public class SFMLImageFileSuffixConverter : StringConverter
|
|
||||||
{
|
|
||||||
private readonly string[] supportedFileSuffix = [".png", ".jpg", ".tga", ".bmp"];
|
|
||||||
|
|
||||||
public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) => true;
|
|
||||||
|
|
||||||
public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context) => true;
|
|
||||||
|
|
||||||
public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context)
|
|
||||||
{
|
|
||||||
return new StandardValuesCollection(supportedFileSuffix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SFMLColorConverter : ExpandableObjectConverter
|
public class SFMLColorConverter : ExpandableObjectConverter
|
||||||
{
|
{
|
||||||
private class SFMLColorPropertyDescriptor : SimplePropertyDescriptor
|
private class SFMLColorPropertyDescriptor : SimplePropertyDescriptor
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
@@ -45,4 +46,46 @@ namespace SpineViewer
|
|||||||
return base.ConvertFrom(context, culture, value);
|
return base.ConvertFrom(context, culture, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class StringEnumConverter : StringConverter
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 字符串标准值列表属性
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
|
||||||
|
public class StandardValuesAttribute : Attribute
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 标准值列表
|
||||||
|
/// </summary>
|
||||||
|
public ReadOnlyCollection<string> StandardValues { get; private set; }
|
||||||
|
private readonly List<string> standardValues = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 字符串标准值列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="values">允许的字符串标准值</param>
|
||||||
|
public StandardValuesAttribute(params string[] values)
|
||||||
|
{
|
||||||
|
standardValues.AddRange(values);
|
||||||
|
StandardValues = standardValues.AsReadOnly();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) => true;
|
||||||
|
|
||||||
|
public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context) => true;
|
||||||
|
|
||||||
|
public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context)
|
||||||
|
{
|
||||||
|
// 查找属性上的 StandardValuesAttribute
|
||||||
|
var attribute = context?.PropertyDescriptor?.Attributes.OfType<StandardValuesAttribute>().FirstOrDefault();
|
||||||
|
StandardValuesCollection result;
|
||||||
|
if (attribute != null)
|
||||||
|
result = new StandardValuesCollection(attribute.StandardValues);
|
||||||
|
else
|
||||||
|
result = new StandardValuesCollection(Array.Empty<string>());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user