I want to implement a custom attribute that, using stopwatch, will measure the running time of the code. I connected the attribute to the main method. But nothing is displayed on the console. I do not understand how to write such an attribute correctly?
[AttributeUsage(AttributeTargets.All )] class TestAttribute : Attribute { private Stopwatch stopwatch; public void RunTime() { stopwatch = new Stopwatch(); stopwatch.Start(); } public void ShowTime() { stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); } } class Program { [TestAttribute] static void Main(string[] args) { } }