© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
20 replies
zobweyt

Attributes confusion

hey! I'm having trouble choosing an approach when using attributes.

I'm building a wrapper around
System.Threading.RateLimiting
System.Threading.RateLimiting
. I have an attribute
RateLimitAttribute
RateLimitAttribute
which is responsible for the basic logic and creation of
PartitionedRateLimiter
PartitionedRateLimiter
.

here’s the problem: I want to be able to create custom ignore policies (to have no limit in custom conditions) and pass them directly to the
RateLimitAttribute
RateLimitAttribute
, but I don’t know how to do this correctly and what approach to choose.

initially I wanted to make a base class
RateLimitPolicyAttribute
RateLimitPolicyAttribute
for all policies and later use it like this:
[RateLimit]
[IgnoreOwner, IgnoreAdmins, IgnorePremiumUsers]
public static void Foo() => throw NotImplementedException();
[RateLimit]
[IgnoreOwner, IgnoreAdmins, IgnorePremiumUsers]
public static void Foo() => throw NotImplementedException();

but the policies here can exist without the main
RateLimitAttribute
RateLimitAttribute


also, I thought about passing the policies directly to the main attribute, but this approach is not possible because the values in attribute parameters must be constant, so I can't just pass a list of policies. additionally, it'll be a very long line in length if I have many policies

how can I implement this most conveniently?
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

❔ Generalise Attributes?
C#CC# / help
3y ago
✅ Equality confusion
C#CC# / help
4mo ago
✅ Serilog Confusion
C#CC# / help
11mo ago
❔ Array confusion..
C#CC# / help
3y ago