94 lines
2.3 KiB
C#
94 lines
2.3 KiB
C#
using JD.Kernel.Classes;
|
|
using JD.Kernel.StaticHelpers;
|
|
|
|
namespace JD.TeaBoxAddinSystem.Addins
|
|
{
|
|
/// <summary>
|
|
/// Describes a property deserialized by a StringPropertyConverter
|
|
/// </summary>
|
|
public class StringPropertyDescriptor
|
|
{
|
|
#region Variables
|
|
|
|
private readonly ValueMemberInfo m_memberInfo;
|
|
private readonly StringPropertyConverterAttribute m_attribute;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Constructor.
|
|
/// </summary>
|
|
/// <param name="memberInfo"></param>
|
|
/// <param name="attribute"></param>
|
|
public StringPropertyDescriptor(ValueMemberInfo memberInfo, StringPropertyConverterAttribute attribute)
|
|
{
|
|
Throw.IfNull(memberInfo, "memberInfo");
|
|
Throw.IfNull(attribute, "attribute");
|
|
|
|
m_memberInfo = memberInfo;
|
|
m_attribute = attribute;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Member that the property describes.
|
|
/// </summary>
|
|
public ValueMemberInfo MemberInfo
|
|
{
|
|
get
|
|
{
|
|
return m_memberInfo;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attribute.
|
|
/// </summary>
|
|
public StringPropertyConverterAttribute Attribute
|
|
{
|
|
get
|
|
{
|
|
return m_attribute;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Name of the serialized property.
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return !string.IsNullOrEmpty(Attribute.Name) ? Attribute.Name : MemberInfo.Name;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// Gets the property descriptor corresponding to the given <paramref name="memberInfo"/>.
|
|
/// </summary>
|
|
/// <param name="memberInfo"></param>
|
|
/// <returns></returns>
|
|
public static StringPropertyDescriptor FromValueMemberInfo<T>(ValueMemberInfo memberInfo) where T : StringPropertyConverterAttribute
|
|
{
|
|
T attribute = memberInfo.GetAttribute<T>(true);
|
|
|
|
if (attribute != null)
|
|
{
|
|
return new StringPropertyDescriptor(memberInfo, attribute);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|