using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Diagnostics;
namespace AttrTestControl
{
[MyAttr("构造中",Desc="属性")]
public class Program
{
static void Main(string[] args)
{
Assembly a = Assembly.LoadFrom(Process.GetCurrentProcess().ProcessName + ".exe");
Type type = typeof(Program);
foreach (Attribute attr in type.GetCustomAttributes(true))
{
MyAttrAttribute newAttr = attr as MyAttrAttribute;
if(newAttr!=null)
Console.WriteLine(newAttr.Desc);
}
Console.ReadLine();
}
}
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
class MyAttrAttribute : Attribute
{
private string _Desc;
/// <summary>
/// Desc
/// </summary>
public string Desc
{
get
{
return _Desc;
}
set
{
_Desc = value;
}
}
public MyAttrAttribute(string sDesc)
{
_Desc = sDesc;
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Diagnostics;
namespace AttrTestControl
{
[MyAttr("构造中",Desc="属性")]
public class Program
{
static void Main(string[] args)
{
Assembly a = Assembly.LoadFrom(Process.GetCurrentProcess().ProcessName + ".exe");
Type type = typeof(Program);
foreach (Attribute attr in type.GetCustomAttributes(true))
{
MyAttrAttribute newAttr = attr as MyAttrAttribute;
if(newAttr!=null)
Console.WriteLine(newAttr.Desc);
}
Console.ReadLine();
}
}
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
class MyAttrAttribute : Attribute
{
private string _Desc;
/// <summary>
/// Desc
/// </summary>
public string Desc
{
get
{
return _Desc;
}
set
{
_Desc = value;
}
}
public MyAttrAttribute(string sDesc)
{
_Desc = sDesc;
}
}
}