Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply Attribute with AttributeTargets = Method to all methods in a class

There is an Attribute called DataSourceAttribute in C#. It needs to be declared on each Method again and again. Is it possible to declare it one time at the class level so that I don't need to repeat myself. If so, how?

In Data Driven UnitTesting, the data source need to be specified with the help of this attribute: [DataSource (...),...]. There are about 10-15 such methods, and I do not want to declare the attribute for each method. I'd like to declare it once and have all the methods inherit it from the class level usage.

like image 632
Pratyush Avatar asked Nov 05 '22 21:11

Pratyush


1 Answers

Take a look at Afterthough. It is a framework that applies custom chunks of code, including properties, methods, attributes to your solution post-compile.

like image 129
armen.shimoon Avatar answered Nov 11 '22 14:11

armen.shimoon