Click here to Skip to main content
15,892,809 members
Articles / Programming Languages / C#

Get CustomAttributes the easy way....

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
16 Apr 2010CPOL 12.2K   2  
A few extension methods to help out.....// Project: Salient.Reflection// http://salient.codeplex.comusing System;using System.Collections.Generic;using System.Linq;using System.Reflection;public static class AttributeHelpers{ /// /// Returns first...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
15 Apr 2010Wouter Ballet
I have a similar set of extension methods, but instead of MemberInfo, I used ICustomAttributeProvider, which is a more general approach as MemberInfo implements this interface. This would make the extensions usable on the types Assembly and Module to name just a few...Regards,Wouter
Please Sign up or sign in to vote.
15 Apr 2010tonyt
How about typing the 'this' parameter as ICustomAttributeProvider ?Also, ToList(...).Where(...) is bad Linq usage, becauseToList() triggers enumeration of the sequence. Try Where(...).ToList() instead.And the ToList() in 'ToList().FirstOrDefault(...)' is entirely pointless.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Salient Solutions
United States United States
My name is Sky Sanders and I am an end-to-end, front-to-back software solutions architect with more than 20 years experience in IT infrastructure and software development, the last 10 years being focused primarily on the Microsoft .NET platform.

My motto is 'I solve problems.' and I am currently available for hire.

I can be contacted at sky.sanders@gmail.com

Comments and Discussions