Sign in
|
Join
Search
~mkw
Average guy, above average luck...the blog of M. Keith Warren
Home
About
RSS
Atom
Comments RSS
Recent Posts
Three things I learned while not in college
ASP.NET solves cellular coverage issues !?
Making us all look bad...
Does adding developers increase the hours?
Origami Hype == Success
Tags
.NET
ASP.NET
ASP.NET Tips and Tricks
C# Tips and Tricks
Community News
General Software Development
MicroISV
Navigation
Home
Blogs
Great .NET Products
PVAM
My Wife's Sites
Hair Bows By Design
Create-A-Bow
Other Communities
KY Dot Net UG
My Old School
Archives
June 2007 (1)
December 2006 (1)
May 2006 (1)
April 2006 (1)
March 2006 (1)
January 2006 (2)
November 2005 (1)
October 2005 (2)
September 2005 (1)
July 2005 (3)
June 2005 (7)
April 2005 (4)
March 2005 (2)
February 2005 (1)
January 2005 (1)
August 2004 (1)
June 2004 (3)
May 2004 (4)
April 2004 (6)
March 2004 (3)
February 2004 (1)
January 2004 (5)
December 2003 (7)
November 2003 (3)
October 2003 (4)
September 2003 (5)
August 2003 (6)
July 2003 (2)
June 2003 (1)
May 2003 (2)
April 2003 (9)
March 2003 (1)
June 2003 - Posts
Using inheritance to limit GetCustomAttributes array size
OK, here is the deal – I want to get back an array of all the custom attributes assigned to my class. In my instance I have three custom attributes I have applied to the class. When I call GetCustomAttributes against the type I only want to see the custom attributes that I have added, not all the ones the ASP.NET runtime adds. When I ran my test I was getting an array of 13 attributes which included System.ComponentModel attributes that I don’t care about. How do you get rid of them? Create a BaseAttribute class derived from System.Attribute and then derive your attribute classes from this BaseAttribute class. Then use the GetCustomAttributes(System.Type, bool inherited) overload and pass in a reference to your BaseAttribute class as the type. This will cause your array to be limited to only attributes that derive from your base class; in my instance limiting to only the 3 custom attributes that I added!
Posted:
Jun 06 2003, 02:36 PM
by
mkeithwarren
| with
1 comment(s)
Filed under:
C# Tips and Tricks
More Posts