473,804 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding attributes at runtime


hi

Is there a "simple" way to add attributes to a class/property at
runtime?

What I try to do is set the default editor for a class/property at
runtime (I know I can set this very easy by decorating the class/
property code), but I would like to do this at runtime.

Is there another way to tell the PropertyGrid what editor to use for a
class/property ?

thanks,
florin

Aug 15 '07 #1
5 3674
florin,

If you want to add attributes to a type at runtime, then you really
can't, as a type is supposed to be static throughout the lifetime of an app,
and that includes attributes.

However, the PropertyGrid uses Type Descriptors, which have a more
limited context, and will give you what you want. Basically, you want to
create a shim class which implements the ICustomTypeDesc riptor interface,
and return the property descriptors, method descriptors, and all the as well
as the Attributes that are associated with it.

Check out the .NET matters column in MSDN Magazine from April and May
2005 for an article which will help you with what you are looking for:

http://msdn.microsoft.com/msdnmag/is...04/NETMatters/
http://msdn.microsoft.com/msdnmag/is...05/NETMatters/
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"florin" <df****@gmail.c omwrote in message
news:11******** **************@ 19g2000hsx.goog legroups.com...
>
hi

Is there a "simple" way to add attributes to a class/property at
runtime?

What I try to do is set the default editor for a class/property at
runtime (I know I can set this very easy by decorating the class/
property code), but I would like to do this at runtime.

Is there another way to tell the PropertyGrid what editor to use for a
class/property ?

thanks,
florin

Aug 15 '07 #2
Note that when talking about a Type (rather than an instance), then
the 2.0 TypeDescription Provider implementation can be more versatile.

Something else to look at: TypeDescriptor. AddAttributes()
http://msdn2.microsoft.com/en-us/lib...tw(VS.80).aspx

I've never used it, but it looks promising. Note that this only
affects the *component-model* (which is what any UI work should be
using anyway) - it would affect reflection, which looks at the
definitions at the point of compilation.

Marc

Aug 15 '07 #3
Replace:

it would affect reflection

With:

it wouldn't affect reflection
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Marc Gravell" <ma**********@g mail.comwrote in message
news:11******** **************@ 19g2000hsx.goog legroups.com...
Note that when talking about a Type (rather than an instance), then
the 2.0 TypeDescription Provider implementation can be more versatile.

Something else to look at: TypeDescriptor. AddAttributes()
http://msdn2.microsoft.com/en-us/lib...tw(VS.80).aspx

I've never used it, but it looks promising. Note that this only
affects the *component-model* (which is what any UI work should be
using anyway) - it would affect reflection, which looks at the
definitions at the point of compilation.

Marc

Aug 15 '07 #4
You are absolutely right... slippy fingers - honest! I hope it was
clear from context that this is what I meant ;-(

Marc
Aug 16 '07 #5
ok, thanks guys!

at least right now I have a starting point, an not 5 :)

florin

Aug 16 '07 #6

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

Similar topics

2
9309
by: Maersa | last post by:
hi, i'm trying to add "attributes" to some nodes and it works at design time but fails at runtime. XmlDocument doc = new XmlDocument(); XmlElement elem = doc.CreateElement( "root" ); elem.InnerXml = "<first>abcde</first><last>1234</last>";
9
5489
by: James Geurts | last post by:
Hey all... I posted this in the vs.net ide group too, but people are not answering, so I figured that it might be more appropriate here. I'm not sure if I'm adding a designer to my code properly. I'm only adding it to the tree node, where each custom tree node is then added to a normal tree control I'm trying to get an add-in to interact with the property window in VS.Net. Basically, I created a tool window containing a custom tree...
1
5649
by: Rob | last post by:
I would like to add the Serializable attribute to an object at runtime. I want to send a System.Web.Mail.MailMessage over the line using Remoting, but MailMessage is not serializable. Thanks in advance, Rob
3
1395
by: Robert Bull | last post by:
I am trying to add a radio button at runtime in an asp.net web form but I keep getting the error message "type 'RadioButton' must be placed inside a form tag with runat=server". I use the following code: Dim rbYes As New RadioButton() dim sStyle as string sStyle = "POSITION:absolute; TOP: 250px; LEFT: 10px" rbYes.Attributes.Add("style", sStyle) rbYes.Attributes.Add("runat", "server")
5
2815
by: Steven Berkovitz | last post by:
Hi there, I am having a problem where if i add an attribute to a control at runtime the rendered attribute is HTML encoded. For example, on a textbox: textBox.Attributes = "if(x && y) alert('hello');"; Gets rendered as:
2
2533
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article is the usage of "Custom Attribute" in real life project. Can somebody please help me understand where are these informations really helpful in Development Environment; may be a few example(s) will help me understand.
3
1560
by: astruyk | last post by:
Is there a way to add an Attribute to an existing type? Like say I wanted to add a to the List<inttype, how would I go about doing that? Also is there any way to attach Attributes to types at runtime?
3
4080
by: zslevi | last post by:
Can I access the class attributes from a method added at runtime? (My experience says no.) I experimented with the following code: class myclass(object): myattr = "myattr" instance = myclass() def method(x):
1
1943
by: ton | last post by:
Hi, I want to add several textbox to my form during runtime: the code is very simple Lab = New TextBox Lab.ID = "A" & i Lab.Height = 200 Lab.Visible = True Lab.Text = "test"
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10350
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.