.NET custom property attribute?
Posted
by ropstah
on Stack Overflow
See other posts from Stack Overflow
or by ropstah
Published on 2010-03-06T16:08:20Z
Indexed on
2010/03/18
3:11 UTC
Read the original article
Hit count: 560
EDIT: I'd better rephrase: How can I shift the GET-implementation of a Class property to a / using a custom attribute? (I've added instantation vars (classname, propertyname) to the attribute, however I'd rather have these automatically fetched ofcourse.)
Public Class CustomClass
<CustomAttributeClass(ClassName:="CustomClass", PropertyName = "SomeProperty")> _
Public Property SomeProperty() as String
Get() as String
//This implementation should be handled by the attribute class
End Get
Set(Byval value as String)
Me._someProperty = value
End Set
End Property
End Class
Old question:
I want to create a custom property attribute for classes. I can create a class derived from Attribute, and 'mark' the property with the attribute, but where to go from here?
I have a repository where I can quickly get data based on the attributes values. I would like to generalize the behaviour of the property in the attribute but I don't know how to go from here... Any help would be greatly accepted!
Public Class CustomDataAttribute : Inherits Attribute
Private _name As String
Public Sub New(ByVal name As String)
Me.Name = name
End Sub
Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
Me._name = value
End Set
End Property
End Class
Public Class CustomClass
<CustomDataAttribute(Name:="CustomField")> _
Public Property CustomField()
End Property
End Class
© Stack Overflow or respective owner