O'Reilly logo

.NET Framework 4.5 Expert Programming Cookbook by A.P. Rajshekhar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Processing custom attributes via reflection

In the previous recipe, we developed a custom attribute named DefectTrackerAttribute. However, the attribute, by itself, does not do anything. Unless there is an application or library that looks at the class and members tagged/decorated by the attribute, it is just a piece of code that does nothing. So, in this recipe, we will see how to process the class tagged by DefectTrackerAttribute using reflection.

How to do it...

  1. Launch Visual Studio .NET 2012.
  2. Open CustomAttribute.sln.
  3. Open the CookBook.Recipes.Core.DefectTracker project in Add a folder to the project. Name it Processor.
  4. Add a class to the folder and name it DefectTrackerProcessor.
  5. Add the following imports:
    using System.Reflection; using CookBook.Recipes.Core.DefectTracker.Attributes; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required