using Apewer.Internals;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace Apewer
{
///
[Serializable]
[AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)]
public class CaptionAttribute : Attribute
{
private string _title, _description, _remark;
///
public CaptionAttribute(string title = null, string description = null, string remark = null)
{
Title = title;
Description = description;
Remark = remark;
}
///
public string Title
{
get { return _title; }
set { _title = value ?? Constant.EmptyString; }
}
///
public string Description
{
get { return _description; }
set { _description = value ?? Constant.EmptyString; }
}
///
public string Remark
{
get { return _remark; }
set { _remark = value ?? Constant.EmptyString; }
}
///
public static string GetTitle(MethodInfo method, bool inherit = true)
{
if (method == null) return null;
var attributes = method.GetCustomAttributes(typeof(CaptionAttribute), inherit);
if (attributes.Length > 0)
{
var attribute = attributes[0] as CaptionAttribute;
return attribute.Title;
}
return method.Name;
}
}
}