我有這個簡單的程序,問題是代碼永遠達不到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」的實例,例如,與'新的TestClassAttribute()'。 –