0

I want to create an Attribute and want to get the Method by the Attribute(through an List or something like that)

I've created my Attribute

 [System.AttributeUsage(System.AttributeTargets.Method |
                          System.AttributeTargets.Struct)
   ]

 
    public class JobActionHandler : System.Attribute
    {
       
        private JobActions.Actions action;
       

        public JobActionHandler(JobActions.Actions actiogn)
        {
          
            this.action = actiogn;
          
           

        }
    }

But i dont know how to add this to a list so i can access the Method and the ENUM VALUE

Sebastian
  • 17
  • 2
  • It's not clear what you mean by _"access the void value"_, since `void` is explicitly what you write **when there is no value**. But as far as getting the attribute itself, and the `action` value from it, you need to use reflection, to get the `MemberInfo` for the type member you want to look at, and then call `GetCustomAttribute()` on that object to get the attribute itself. See duplicate for an example using properties. It works exactly the same for methods, except you call `GetMethod()` instead of `GetProperty()`. – Peter Duniho Jun 19 '21 at 17:25

0 Answers0