Hi!

>> I thought I would never be allowed to use the setter property in
MyAttribute or change any value whatsoever.

Well, your attribute is just a class, nothing less and nothing more. If you
have a setter for your property, there's nothing to stop you.

>> why was the value not preserved the next time I searched for that same
attribute in the same class instance

I guess that's because when you call propInfo.GetCustomAttributes(...), it
returns a new array of new instances of your attribute.

Cheers,

Stoyan Damov

-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] Behalf Of Roni Burd
Sent: 06/04/2003 04:38
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] Changing CustomAttributep properties on
RunTime


Hi.
I was working with attributes and fund a behavior that I cannot
understand.
I created a CustomAttribute MyAttribute that has getter and setter
properties for a private field. This field is initialized with the
constructor.
Also the attribute is only used with properties
(AttributeTargets.Property).

During my experimentation I realized I can use de setter properties in
the MyAttribute to set the value for a new one. This seems to work,
until I try to get the MyAttribute again from the same property on the
same instance. The value is the one that was set with the ctor.

My understanding of attributes is small so at first I thought I would
never be allowed to use the setter property in MyAttribute or change any
value whatsoever. An even after I was allowed to change the private
field inside MyAttribute, why was the value not preserved the next time
I searched for that same attribute in the same class instance?

Thanks!

Reply via email to