J
Jenny Fletcher
I am trying to dynamically invoke a property of enumeration type but I can't
find a way to get it to work. This is my code which works fine until I call
InvokeMember and I get an ArgumentException. I've tried various combinations
of parameters in my call to InvokeMember but can't find anything that does
the job. Any help would be appreciated.
Jenny
Dim arrObj(0) As Object
Dim objPInfo As PropertyInfo = TextBox1.GetType.GetProperty("ScrollBars")
If Not objPInfo Is Nothing Then
If objPInfo.CanWrite Then
If objPInfo.PropertyType.IsEnum Then
Dim objEnumType As Type = objPInfo.PropertyType
Dim objFieldInfo As FieldInfo = objEnumType.GetField("Both")
If Not objFieldInfo Is Nothing Then
arrObj(0) = Activator.CreateInstance(objEnumType)
arrObj(0).GetType.InvokeMember(objFieldInfo.Name,
BindingFlags.SetField, Nothing, arrObj(0), Nothing)
End If
End If
End If
TextBox1.GetType.InvokeMember("ScrollBars", BindingFlags.SetProperty,
Nothing, TextBox1, arrObj)
find a way to get it to work. This is my code which works fine until I call
InvokeMember and I get an ArgumentException. I've tried various combinations
of parameters in my call to InvokeMember but can't find anything that does
the job. Any help would be appreciated.
Jenny
Dim arrObj(0) As Object
Dim objPInfo As PropertyInfo = TextBox1.GetType.GetProperty("ScrollBars")
If Not objPInfo Is Nothing Then
If objPInfo.CanWrite Then
If objPInfo.PropertyType.IsEnum Then
Dim objEnumType As Type = objPInfo.PropertyType
Dim objFieldInfo As FieldInfo = objEnumType.GetField("Both")
If Not objFieldInfo Is Nothing Then
arrObj(0) = Activator.CreateInstance(objEnumType)
arrObj(0).GetType.InvokeMember(objFieldInfo.Name,
BindingFlags.SetField, Nothing, arrObj(0), Nothing)
End If
End If
End If
TextBox1.GetType.InvokeMember("ScrollBars", BindingFlags.SetProperty,
Nothing, TextBox1, arrObj)