According to here, attribute constructor will not run until GetCustomAttributes()
method is called.
This will instantiate every attributes owned the class.
What is the most efficient way to force construct a certain custom attribute ? Upon new-ing the class, I only want to instantiate specific attributes, not all of them.
[RegularAttribute("Dont_turn_me_on_yet")]
public class MyClass
{
public int Value { get; set; }
[SpecialAttribute("On_RightAway_Please")]
public void MethodOne(){}
[RegularAttribute("Dont_turn_me_on_yet")]
public void MethodTwo(){}
}
static void Main()
{
var mc = new MyClass(); //SpecialAttribute constructor is called right away, but not RegularAttribute
}