DeviceManager/DeviceRepair.Models/Attr/BoolConverterAttribute.cs
2024-07-27 09:44:19 +08:00

59 lines
1.3 KiB
C#

using System;
using System.Runtime.InteropServices;
namespace DeviceRepair.Models.Attr
{
/// <summary>
/// DOM转换时bool型转换特性
/// </summary>
[Serializable]
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
[ComVisible(true)]
public sealed class BoolConverterAttribute : Attribute
{
#region Fields
/// <summary>
/// 转换类型
/// </summary>
public Type ConvertType
{
get;
set;
}
public string[] BoolString { get; set; }
#endregion
#region Ctor
/// <summary>
/// Ctor
/// </summary>
public BoolConverterAttribute(string boolString)
{
if (string.IsNullOrEmpty(boolString))
{
throw new ArgumentNullException();
}
BoolString = boolString.Split(',');
if (BoolString.Length != 2)
{
throw new ArgumentException("BooleanString格式不符合规定");
}
}
public BoolConverterAttribute()
: this("1,0")
{
ConvertType = typeof(string);
}
#endregion
#region Property
#endregion
}
}