Re: Instance attribute values
From: Rob Teixeira [MVP] (RobTeixeira_at_@msn.com)
Date: 09/22/04
- Next message: Michi Henning: "Re: ByRef.."
- Previous message: rodchar: "inheriting from dataset"
- In reply to: ljlevend: "Instance attribute values"
- Next in thread: ljlevend: "Re: Instance attribute values"
- Reply: ljlevend: "Re: Instance attribute values"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 21 Sep 2004 20:34:20 -0400
Nope. The attributes are affecting Type metadata. This is per Type, not per
instance. Once you compile, that attribute's value is serialized into the
metadata of the assembly. You can create new attributes at runtime with
different values, but the attribute values tied to your Types in the
metadata can't be changed. In other words, if you query using Reflection,
you'll always get the compiled attribute values for a Type or Type member.
Anything in the way of instance data that is manipulated at runtime should
be an instance field.
-Rob Teixeira [MVP]
"ljlevend" <ljlevend@nospam.nospam> wrote in message
news:05152471-5E59-4F05-A26A-1138ABA6F47F@microsoft.com...
> Is there any way to have an attribute with a value that is unique to an
> instance of an object? For example, let say I have the following:
>
> Public Class MyAttribute
> Inherits System.Attribute
> Public Value As Boolean
> Public Sub New(ByVal value As Boolean)
> Me.Value = value
> End Sub
> End Class
>
> Public Class MyClassWithAttribute
> <MyAttribute(True)> _
> Public Property SomeProperty As Object
> ...
> End Property
> End Class
>
> Public Class MyWorkingClass
> Public myClassWithAttribute1 As New MyClassWithAttribute
> Public myClassWithAttribute2 As New MyClassWithAttribute
> ...
> End Class
>
> Now, what I want to do is to be able to set MyAttribute.Value of
> myClassWithAttribute1.SomeProperty to False, but to keep MyAttribute.Value
of
> myClassWithAttribute2.SomeProperty set to True. Is this possible?
>
> Thanks,
> Lance
>
- Next message: Michi Henning: "Re: ByRef.."
- Previous message: rodchar: "inheriting from dataset"
- In reply to: ljlevend: "Instance attribute values"
- Next in thread: ljlevend: "Re: Instance attribute values"
- Reply: ljlevend: "Re: Instance attribute values"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|