Suppose there is some class and before calling some methods I want to call another method.

For example, I want to check the privileges for this operation.

Yes, I can add a function to each method that will do this.

But can it be done in another way?

  • one
    PostSharp watched? - Zufir
  • one
    Not familiar with C #. But it is very likely that you are looking for what is called AOP (aspect-oriented programming). - Arnial
  • Attributes ? - eastwing
  • Firstly, inheritance, a method in the forehead, so to speak, and secondly a decorator pattern, how to fasten a different question, many ways, and then you can look at all kinds of aop. - Primus Singularis

1 answer 1

You can use either PostSharp or do it yourself using the “ Intercepting method calls in C #, an approach to AOSDguide .