c# Attribute Question

Posted by Petoj on Stack Overflow See other posts from Stack Overflow or by Petoj
Published on 2010-04-05T15:42:20Z Indexed on 2010/04/05 15:43 UTC
Read the original article Hit count: 375

Well i need some help here i don't know how to solve this problem.

the function of the attribute is to determine if the function can be run...

So what i need is the following:

  1. The consumer of the attribute should be able to determine if it can be executed.
  2. The owner of the attribute should be able to tell the consumer that now it can/can't be executed (like a event).
  3. It must have a simple syntax.

This is what i have so far but it only implements point 1, 3.

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class ExecuteMethodAttribute : Attribute
{
    private Func<object, bool> canExecute;
    public Func<object, bool> CanExecute
    {
        get
        {
            return canExecute;
        }
    }


    public ExecuteMethodAttribute()
    {

    }

    public ExecuteMethodAttribute(Func<object, bool> canExecute)
    {
        this.canExecute = canExecute;
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about attribute