【发布时间】:2013-06-26 19:53:37
【问题描述】:
我有这个简单的程序,问题是代码永远不会到达 TestClassAttribute 类。控制台输出为:
init
executed
end
代码
class Program
{
static void Main(string[] args)
{
Console.WriteLine("init");
var test = new Test();
test.foo();
Console.WriteLine("end");
Console.ReadKey();
}
public class TestClassAttribute : Attribute
{
public TestClassAttribute()
{
Console.WriteLine("AttrClass");
Console.WriteLine("I am here. I'm the attribute constructor!");
Console.ReadLine();
}
}
public class Test
{
[TestClass]
public void foo()
{
Console.WriteLine("executed");
}
}
}
【问题讨论】:
-
你永远不会构造
TestClassAttribute的实例,例如new TestClassAttribute().
标签: c# attributes