using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Pcb.Common
{
///
/// 帮助属性
///
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
public class InfoAttribute : System.Attribute
{
///
/// 构造
///
///
public InfoAttribute(string name)
{
this.Name = name;
}
///
/// 名称
///
public string Name
{
get;
set;
}
///
/// 描述
///
public string Description
{
get;
set;
}
///
/// 作者
///
public string Author
{
get;
set;
}
///
/// 创建时间
///
public string CreateTime
{
get;
set;
}
///
/// 得到自定义的Attribute名称
///
///
///
public static string GetAttributesName(object[] customAttributes)
{
if (customAttributes == null)
return string.Empty;
string re = string.Empty;
foreach (object obj in customAttributes)
{
if (obj == null) continue;
if (obj is InfoAttribute)
{
InfoAttribute at = (InfoAttribute)obj;
if (at.Name != null)
{
re = at.Name.Trim();
break;
}
}
}
return re;
}
///
/// 取属性名称
///
///
///
///
public static string GetProprtyAttributeName(Type type, string proprtyName)
{
if (type == null)
return string.Empty;
foreach (System.Reflection.PropertyInfo p in type.GetProperties())
{
if (p.Name == proprtyName)
{
return InfoAttribute.GetAttributesName(p.GetCustomAttributes(true));
}
}
return string.Empty;
}
///
/// 取方法名称
///
///
///
///
public static string GetFunctionAttributeName(Type type, string proprtyName)
{
if (type == null)
return string.Empty;
foreach (System.Reflection.MemberInfo p in type.GetMethods())
{
if (p.Name == proprtyName)
{
return InfoAttribute.GetAttributesName(p.GetCustomAttributes(true));
}
}
return string.Empty;
}
//---
}
}