Answer the question
In order to leave comments, you need to log in
How to use attributes to apply a method to all other methods of a class in C#?
I want to implement validation (authorization and other calculations) for all class methods.
That is, when executing each method of the class, I want to first perform a certain check, and if it is passed, then execute the method further.
In fact, before each class method, write the execution of the check method.
Is it possible to implement this using attributes or abstract classes, or inheritance, so as not to write the execution of the check method every time, but to create a certain structure?
Answer the question
In order to leave comments, you need to log in
If we are talking about asp.net, then there is a special attribute on this topic
c# custom attribute example
Well, if this does not help, then there is the Attribute class, from which you need to inherit and make your own implementation.
public class MyCustomAttribute: Attribute
{
public string SomeProperty { get; set; }
}
[MyCustom(SomeProperty = "foo bar")]
public class Foo
{
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question