你啥都没干,怎会执行呢,给你个连接学习一下
http://www.cnblogs.com/dc10101/archive/2009/03/24/1420199.html
http://www.cnblogs.com/dc10101/archive/2009/03/24/1420199.html
解决方案 »
- c# IC卡的问题 冰天雪地 寒风刺骨 鼻涕四溅 空中转体720°挥泪求指教急急
- 请教:有谁遇到过这样的错误 Length cannot be less than zero
- (急) C# ASP.NET网站模板
- winform中button点击如何执行webBrowser中submit的Click事件?
- ArrayList 的用法 小弟是菜鸟 喜欢钻牛角尖,第一次提问问题 不要鄙视我啊
- 简单C#问题!!!
- 100分请教:如何在.NET中为EXCEL模板的某一行,插入分页符?
- 求C#实现UBB Code功能的代码……
- 在线求助,谢谢!!
- 水晶报表
- 数据验证发送间隔时间计算,间隔时间随着验证超时次数越多而越长。
- System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本
怎么没执行呢,Main执行了静态方法AddUser,那个特性是附加在AddUser方法上的?难道特性在它附加的对象上当被附加对象执行时特性本身不会执行么?
{
UserService.AddUser(); Type classType = typeof(UserService); foreach (MethodInfo method in classType.GetMethods())
{
foreach (Attribute attr in Attribute.GetCustomAttributes(method))
{
if (attr.GetType() == typeof(MyAttribute))
{
MyAttribute att = (MyAttribute)attr;
}
}
}
} class UserService
{
[My]
public static void AddUser()
{
Console.WriteLine("数据写入到数据库成功!");
}
} [AttributeUsage(AttributeTargets.All)]
class MyAttribute : System.Attribute
{
public MyAttribute()
{
Console.WriteLine("=============================");
Console.WriteLine("时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Console.WriteLine("=============================");
}
}
class Program
{
static void Main(string[] args)
{
AddUser();
}
[My]
public static void AddUser()
{
Console.WriteLine("数据写入到数据库成功!");
}
class MyAttribute : System.Attribute
{
public MyAttribute()
{
Console.WriteLine("=============================");
Console.WriteLine("时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Console.WriteLine("=============================");
}
}
}
看行不行