I'm trying to use this method to pass a delegate as a parameter.
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( () =>
{
return Guid.Empty;
}
);
}
}
I'm getting an error when I try to create the delegate with reflection
spaceGetter = (SpaceIdGetter)Delegate.CreateDelegate(delegateType, delegateType.GetMethod(delegateName));
Type must derive from Delegate.
Edit: here's how I'm using it
[SpaceId(typeof(ContextInfo), "GetSpaceId")]
public virtual string Body { get; set; }