I'm implementing system which uses role based access to different methods in classes. For example to perform any action I need to check whether user which uses it can do it.
I can write in each method:
if(User.IsInRole ...) {
} else {
return ... throw ... whatever
}
I was thinking about automating this process for example by adding attributes to this methods or maybe any other solution?
Take a look at 'Aspect Oriented Programming' (AOP) libraries -- and the answers to this StackOverflow question. You can use AOP to add the role check code automatically.