Ist es möglich, einen Delegaten als Attributparameter zu haben?

Ist es möglich, einen Delegaten als parameter ein Attribut?

Wie diese:

public delegate IPropertySet ConnectionPropertiesDelegate();

public static class TestDelegate
{
    public static IPropertySet GetConnection()
    {
        return new PropertySetClass();
    }
}

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface,AllowMultiple=false,Inherited=true)]
public class WorkspaceAttribute : Attribute
{
    public ConnectionPropertiesDelegate ConnectionDelegate { get; set; }

    public WorkspaceAttribute(ConnectionPropertiesDelegate connectionDelegate)
    {
        ConnectionDelegate = connectionDelegate;
    }
}

[Workspace(TestDelegate.GetConnection)]
public class Test
{
}

Und wenn das nicht möglich ist, was sind die sinnvollen alternativen?

InformationsquelleAutor der Frage George Silva | 2011-10-09

Schreibe einen Kommentar