© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
10 replies
Sven ☕

❔ Generalise Attributes?

Is there a way to generalise Attributes?
I'd like to create a library in which I can just pass in what Enum to watch out for.
So I'd like to replace the EPartnership/ECategory enum with any enum passed into the attribute.
What would be the smartest way to get around this?
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class EventPartnershipControllerAttribute : Attribute
{
    public EPartnership Event { get; set; }

    public EventPartnershipControllerAttribute(EPartnership Event)
    {
        this.Event = Event;
    }
}
public class EventController
    {
        [EventControllerAttribute(ECategory.PARTNERSHIP)]
        public static async void PartnershipController(string[] ids, object e)
        {
                    // Foo...
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class EventPartnershipControllerAttribute : Attribute
{
    public EPartnership Event { get; set; }

    public EventPartnershipControllerAttribute(EPartnership Event)
    {
        this.Event = Event;
    }
}
public class EventController
    {
        [EventControllerAttribute(ECategory.PARTNERSHIP)]
        public static async void PartnershipController(string[] ids, object e)
        {
                    // Foo...
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Can I generalise this method?
C#CC# / help
4y ago
Attributes confusion
C#CC# / help
2y ago
❔ Json Model attributes
C#CC# / help
4y ago