我有这个简单的程序,问题是代码永远不会到达 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");
}
}
}