OOP - Adding attribute to an object

ugh3012

Member
Joined
Feb 20, 2007
Messages
13
Programming Experience
5-10
I want to add attributes to an object, but I am not sure how or even if that is possible. For example, I want to add readonly, nameField, etc, to objected called fullname. So, if I type fullname.xxxx I will get a list of attributes. Those attributes are static and it will be hard coded in the module.

This is what I have so far.

VB.NET:
Public Class myClass

  Private sFullName As String

    Property fullName() As String
        Get
            Return sFullName
        End Get
        Set(ByVal Value As String)
            sFullName = Value
        End Set
    End Property
End Class
 
I think that there's relevant information you're not giving us here. Why do you want to do this? If your property is supposed to be read-only then why does it have a public setter?
 
The legacy application’s forms are dynamic and the codes are mess and hard to maintain. I thought that if I could add attributes to fullname, address1, etc. It would be easy to maintain the dynamic form. As the form is being built, I could access the attributes and set the necessary properties to the control, such as control type, read only , etc.

Of course, I am open to other ideas.
 
You can decorate a property with any existing attribute that supports properties or you can define your own attributes if you want. An attribute is just a class that inherits System.Attribute. You can indeed then get the attributes on a particular property at run time.
 
Back
Top