• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Finding out if a property exists in an object

brandonb

Diamond Member
I'm not completely new to .net but this is the first time I've had to do this. I am doing a project with alot of polymorphism and i need to determine if a property exists in an object without knowing ahead of time the type of the object.

I have a propertygrid control which takes any number of classes to fill out the propertygrid control with properties.

I have a base class that is trying to see if the propertygrid has a certain parameter to know how to manipulate the screen accordingly which not all classes contain.

Is this possible?

Thanks in advance!
 
Thanks for the tip! Got it working:

Dim objl_PROPERTYINFO As System.Reflection.PropertyInfo
objl_PROPERTYINFO = objm_PROPERTYCLASS.GetType().GetProperty("Today")

If Not objl_PROPERTYINFO Is Nothing Then
If objm_PROPERTYCLASS.Today = False Then
objm_REFRESH.Checked = False
objm_TIMER.Enabled = False
Else
objm_REFRESH.Checked = True
objm_TIMER.Enabled = True
End If
End If
 
Thanks a lot for posting the solution back to the board, Brandon!
 
Recently I had to write a class that implements IComparer to sort a generic List of some business objects, given one of the object's properties, and it used that PropertyInfo class and GetProperty method. I got the snippet of code from somewhere else but this is something that could definitely come in handy. :beer:
 
Back
Top