I have create a attribute to process some info before a method is called but it is not getting called.
I want to log some values which are process and stored in a static field in the class, as a result of other methods of my class called.
So can someone guide on it.
[AttributeUsage(AttributeTargets.Method)]
internal class MyAttrib : Attribute
{
public MyAttrib()
{
//This is not getting called. what am i missing
Console.WriteLine("My Attrib called!!");
}
}
class MyClass
{
public MyClass()
{
Console.WriteLine("Constructor Created");
}
[MyAttrib]
public int Opt1()
{
Console.WriteLine("Op1 Performed");
return 0;
}
}
static void Main(string[] args)
{
MyClass cla = new MyClass();
cla.Opt1();
cla.Opt2();
Console.ReadLine();
}