You can, but not as brief as in your question.
This function will receive any property of any object by name.
Public Function GetPropertyValue(ByVal obj As Object, ByVal PropName As String) As Object Dim objType As Type = obj.GetType() Dim pInfo As System.Reflection.PropertyInfo = objType.GetProperty(PropName) Dim PropValue As Object = pInfo.GetValue(obj, Reflection.BindingFlags.GetProperty, Nothing, Nothing, Nothing) Return PropValue End Function
I leave you error handling. And any consequences :)
Miroslav zadravec
source share