Why does my .NET Attribute not perform an action?

后端 未结 3 1052
遇见更好的自我
遇见更好的自我 2021-01-06 00:27

I\'ve created a simple Attribute:

[AttributeUsage(AttributeTargets.Method)]
public class InitAttribute : System.Attribute
{
    public InitAttribute()
    {
         


        
3条回答
  •  孤城傲影
    2021-01-06 01:18

    If you need to perform an action as control enters a method, you should look at aspect-oriented programming and frameworks such as PostSharp. Attributes are not designed to perform anything by themselves. They are just a bunch of data (or metadata if you will) attached to stuff in IL assemblies that can be queried at runtime.

提交回复
热议问题