title: Passing a delegate as an Attribute
body: <p>I'm trying to use <a href="https://stackoverflow.com/questions/7705386/is-it-possible-to-have-a-delegate-as-attribute-parameter">this</a> method to pass a delegate as a parameter.</p>
  
  <pre><code>public delegate Guid SpaceIdGetter();
  public class SpaceIdAttribute : Attribute
      {
          public SpaceIdGetter spaceGetter { get; set; }
  
          public SpaceIdAttribute(Type delegateType, string delegateName)
          {
              spaceGetter = (SpaceIdGetter)Delegate.CreateDelegate(delegateType, delegateType.GetMethod(delegateName));
          }
      }
  
      public static class ContextInfo
      {
          public static SpaceIdGetter GetSpaceId()
          {
              return new SpaceIdGetter( () =&gt;
                      {
                          return Guid.Empty;
                      }
                  );
          }
      }
  </code></pre>
  
  <p>I'm getting an error when I try to create the delegate with reflection </p>
  
  <pre><code>spaceGetter = (SpaceIdGetter)Delegate.CreateDelegate(delegateType, delegateType.GetMethod(delegateName));
  </code></pre>
  
  <blockquote>
    <p>Type must derive from Delegate.</p>
  </blockquote>
  
  <p>Edit: here's how I'm using it</p>
  
  <pre><code>[SpaceId(typeof(ContextInfo), "GetSpaceId")]
  public virtual string Body { get; set; }
  </code></pre>