E
Etienne-Louis Nicolet
I am working on an error handler class. Within a property set method of a
given class property I'd like to pass the PropertyInfo to a function.
Imagine something like:
Public Class MyClass
....
Public Property MyProperty() as String
Get
Return _myProperty
End Get
Set (ByVal pMyProperty as String)
' Validate property. If there's an error, add an item to the
error handler
MyErrorHandler.AddError([MyProperty], errorCode) ' <--- How to
get the reference to 'MyProperty'?
End Set
End Property
....
End Class
Public Class MyErrorHandler
....
Public Sub AddError(ByVal pProperty As System.Reflection.PropertyInfo,
pErrorCode As Integer)
....
End Sub
....
End Class
Many thanks to Bill McCarthy who suggested to do something like:
MyErrorHandler.AddError(GetType(TheClass).GetProperty("MyProperty").
I'd rather like to use a statement that does not hard-code the property
name, but rather uses intellisense, which makes code less vulnerable to
possible changes.
Many thanks for any ideas,
Etienne
given class property I'd like to pass the PropertyInfo to a function.
Imagine something like:
Public Class MyClass
....
Public Property MyProperty() as String
Get
Return _myProperty
End Get
Set (ByVal pMyProperty as String)
' Validate property. If there's an error, add an item to the
error handler
MyErrorHandler.AddError([MyProperty], errorCode) ' <--- How to
get the reference to 'MyProperty'?
End Set
End Property
....
End Class
Public Class MyErrorHandler
....
Public Sub AddError(ByVal pProperty As System.Reflection.PropertyInfo,
pErrorCode As Integer)
....
End Sub
....
End Class
Many thanks to Bill McCarthy who suggested to do something like:
MyErrorHandler.AddError(GetType(TheClass).GetProperty("MyProperty").
I'd rather like to use a statement that does not hard-code the property
name, but rather uses intellisense, which makes code less vulnerable to
possible changes.
Many thanks for any ideas,
Etienne