473,394 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Adding attribute to System types

Is there a way to add an Attribute to an existing type? Like say I
wanted to add a [MyCustomAttribute] to the List<inttype, how would I
go about doing that?

Also is there any way to attach Attributes to types at runtime?

Dec 21 '06 #1
3 1542
You can add attributes to type at runtime but only in a very special
circumstance.

Any object subject to reflection can be given a TypeDescriptionProvider.
This enables the TypeDescriptor to return any custom information yo may
desire, including dynamically created attributes, extra properties and
so-on.

Normally attributes are compiler generated, fixed and only instantiated when
reflection is used.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

<as*****@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
Is there a way to add an Attribute to an existing type? Like say I
wanted to add a [MyCustomAttribute] to the List<inttype, how would I
go about doing that?

Also is there any way to attach Attributes to types at runtime?

Dec 21 '06 #2
Hi,

Why do you need to add an attribute to an FCL type?

(BTW, you couldn't add an attribute to List<intanyway since it doesn't
exist. List<Tis the class).

You could derive a class from List<intand add a custom attribute to that
if you want.

--
Dave Sexton

<as*****@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
Is there a way to add an Attribute to an existing type? Like say I
wanted to add a [MyCustomAttribute] to the List<inttype, how would I
go about doing that?

Also is there any way to attach Attributes to types at runtime?

Dec 22 '06 #3
I'm using Attributes to indicate to a class what types should be
ignored while processing data using reflection. Using the
TypeDescriptor seems to be working, as long as you check for the
Attribute using the TypeDescriptor and not just the
Type.GetCustomAttributes()...

Dave Sexton wrote:
Hi,

Why do you need to add an attribute to an FCL type?

(BTW, you couldn't add an attribute to List<intanyway since it doesn't
exist. List<Tis the class).

You could derive a class from List<intand add a custom attribute to that
if you want.
Dec 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Rock | last post by:
Hello, I have a web method that serializes a class that includes among its public fields a System.Object field to which, at runtime, I assign instances of various different classes. When...
1
by: seanmayhew | last post by:
I have a form page that that while editing saves the data to an xml doc before submitting to db. On each page unload it saves the xmldoc as the user can add multiple items to the company like...
4
by: Joe | last post by:
I have an xml file which looks similar to this: <data> Please enter the value: <dynamicControl id="myDC", type="Textbox", MaxLength="100"/> </data> I am trying to devise a way to have a web...
3
by: MIGUEL | last post by:
Hi all, I'm quite lost with how adding web references to a project creates proxy classes. I've developed a web service with two classes inside and that contains three references to three...
2
by: Mike Fiedler | last post by:
On a client web services request, I have a SoapExtension that is adding a header to the message in the BeforeSerialize stage. If the Web Service request is for an operation with...
4
by: glebur | last post by:
Hi, I'm trying to create a web service client in C# but I get stuck at one of the first steps. When adding a Web reference to the Visual Studio project; I get this error (this is a translation,...
3
by: Jonathan Wood | last post by:
I could really use some help on this. First of all, I want to create a Web control where I render the control completely from scratch based on information from a database. In the book...
10
by: Nathan Laff | last post by:
I have a custom attribute which i use for fields in an enum. I want to pass around a delegate in these things. so i want to do something like this Is this possible? i'm having no luck.
1
by: hardieca | last post by:
Hi! I decorate my unfinished classes and methods with a custom TODO attribute (as in things To Do). Using reflection, I am then able to parse through my classes and output all TODOs to a list I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.