Coolest function of the day, call an objects method using a variable, Dynamically invoke properties by string name using VB.NET

So I had always wanted to be able to do something like this

dim myDog as new dogobject

dim methodVariable as string = “bark”


i.e. call a method by using a variable

Well, after some serious googling, I finally ran across this function CallByName

this allows me to do this


or if you wanted to iterate through ever method in the object you could do

Dim pdc As System.ComponentModel.PropertyDescriptorCollection
pdc = System.ComponentModel.TypeDescriptor.GetProperties(myDog.GetType)

For Each pd As System.ComponentModel.PropertyDescriptor In pdc