0

I want to create my own Attribute in C# .Net with an argument of Action type, like this:

 public class TestAttribute : Attribute
 {
        public Action MethodToExecute;
 }

And the use:

 [TestAttribute(MethodToExecute = () => Test())]
 public string VersaoLinha { get; set; }

 public static string Test()
 {
     return string.Empty;
 }

But so, I've the error Is not a valid argument because it is not a valid attribute parameter type. Has a way to do this?

Only a Curious Mind
  • 2,807
  • 23
  • 39
  • 3
    Similar to this - http://stackoverflow.com/questions/7705386/is-it-possible-to-have-a-delegate-as-attribute-parameter – Daniel Kelley Jun 11 '14 at 12:10
  • 1
    And to this http://stackoverflow.com/questions/3357569/passing-func-as-an-attribute-parameter-to-secure-mvc-routes – eternity Jun 11 '14 at 12:11

0 Answers0