






















C# Attribute class
[AttributeUsage(AttributeTargets.Method)]
public class FastyouAttribute:Attribute
{
private string _name = string.Empty;
public FastyouAttribute(string name)
{
_name = name;
}
public string Name
{
get { return _name; }
set { _name = value; }
}
}
应用这个类
public class AttributeClass
{
[Fastyou("what's your name")]
public void getName()
{
//string name = "name";
}
}
访问结果
public void AttributeFastyou()
{
Type type = typeof(AttributeClass);
foreach (MethodInfo mothod in type.GetMethods())
{
foreach (Attribute at in mothod.GetCustomAttributes(true))
{
FastyouAttribute att = at as FastyouAttribute;
if (att != null)
{
string sss = att.Name;//"what's your name"
string ddd = mothod.Name;//getName
}
}
}
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。