Test if a class has an attribute?

前端 未结 4 615
再見小時候
再見小時候 2020-12-05 03:52

I\'m trying to do a little Test-First development, and I\'m trying to verify that my classes are marked with an attribute:

[SubControllerActionToViewDataAttr         


        
4条回答
  •  感情败类
    2020-12-05 04:26

    It is also possible to use generics on this:

    var type = typeof(SomeType);
    var attribute = type.GetCustomAttribute();
    

    This way you do not need another typeof(...), which can make the code cleaner.

提交回复
热议问题