C
C#5mo ago
ægteemil

✅ Apply multiple attributes from custom attribute

Hey. I want to encapsulate some duplicated logic from a custom attribute. Right now I'm decorating endpoints with multiple attributes, and I'd like to be apply to just apply my own custom attribute, and have that attribute apply multiple other attributes. So my custom attribute would look like this(?):
public class TestAttribute : Attribute
{
[MyFirstAttribute(name)]
[MySecondAttribute(name)]
public TestAttribute(string name)
{
Name = name;
}

public string Name { get; }
}
public class TestAttribute : Attribute
{
[MyFirstAttribute(name)]
[MySecondAttribute(name)]
public TestAttribute(string name)
{
Name = name;
}

public string Name { get; }
}
6 Replies
Anton
Anton5mo ago
no you can't but aspnet core generally works with interfaces and not the concrete attributes you can implement those in yours look at what interfaces those attributes implement also you can apply those to the controller people generally make a controller base class with these
VoidPointer
VoidPointer5mo ago
I second @Anton 's base controller approach. Always worked great for me when I was still working with controllers.
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX5mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
ægteemil
ægteemilOP5mo ago
Sorry, I didn't see oyur message until now. Seems it got closed for me. Thanks!
Want results from more Discord servers?
Add your server