问题
[CustomMethodAttribute]
public void MyMethod(string[] args)
{
// Some implementation
}
When will CustomMethodAttribute be evaluated and can you do anything to change when this evaluation takes place? Also, care to explain exactly how the compiler manages this trick?
回答1:
When will CustomMethodAttribute be evaluated and can you do anything to change when this evaluation takes place?
In general, there is no evaluation that takes place. A custom attribute is added to the method as metadata, and available to be inspected via reflection at runtime as needed.
For details, see Attributes on MSDN.
来源:https://stackoverflow.com/questions/21004932/when-are-method-attributes-evaluated