C#C
C#2y ago
zobweyt

Attributes confusion

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

I'm building a wrapper around
System.Threading.RateLimiting
. I have an attribute
RateLimitAttribute
which is responsible for the basic logic and creation of
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
, but I don’t know how to do this correctly and what approach to choose.

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

but the policies here can exist without the main
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?
Was this page helpful?