I have the following C# code
class Program
{
[My]
static void Main(string[] args)
{
SomeMethod();
}
[My]
static void SomeMethod()
{
Console.WriteLine("1111");
}
}
public class MyAttribute: Attribute
{
public MyAttribute()
{
MessageBox.Show("enter");
}
~MyAttribute()
{
MessageBox.Show("leave");
}
}
Attribute My applies only to method Main (constructor of MyAttribute executes on entering the Main method and destructor executes on leaving them), but not for method SomeMethod.
I need feature like this: execute some portion of code (start and kill the process) in some methods, without modifying them (I think, that the attributes may be the best decision).
Please, help