I am creating .NET validators dynamically and passing the property I am invoking and the value to a method that invokes the property and supplies the value.
This is working for most of the properties. But when I try to invoke the Operator method or the Type method of the compare validator, I get an error saying the property cannot be found. The code I am using is below. I know it needs error handling, but I'm still in early development and want to see where it blows up. Through the debugger, I can see that the paramater supplied as Obj is indeed a CompareValidator and does have the properties that cannot be found. I thought it might only be finding the base properties, (I downcast to base validator in the caller), but it works on ControlToCompare which is not a member of BaseValidator. Any help would be appreciated.
''' <summary>
''' Invokes a property on the supplied object
''' </summary>
''' <param name="Obj">Object to invoke the property on</param>
''' <param name="PropertyName">Name of the property to invoke</param>
''' <param name="PropertyValue">Value of the property</param>
''' <returns></returns>
''' <remarks>Uses reflection to invoke the property</remarks>
Private Function InvokeProperty(ByVal Obj As Object, ByVal PropertyName As String, ByVal PropertyValue As String) As Object
Dim Params(0) As String
Params(0) = PropertyValue
Return Obj.GetType().InvokeMember(PropertyName, Reflection.BindingFlags.SetProperty, Nothing, Obj, Params)
End Function