It turns out that MS has decided not to include GetProperty function to NETMF while including GetMethod. I hardly can imagine what could be a reason for this, but anyway. I need to set property’s value using property’s name. Something like this:
In this case solutions like changing properties to methods, making a dictionary that includes all property' names and alike are not suitable.
What are my options? I need it badly :(
I don’t. What I’m saying is if you derived a class from an interface known to the calling app domain you could create it as an instance of the interface and use the associated properties.
I want to make an universal plug-in, so I would prefer not to modify present code. That’s why I was looking into Reflection.
But if I agree to do a slight modification, how should it look like? Let’s take this example:
Partial Public Class Program
Public Sub ProgramStarted()
SetPropertyByName("SetMe", True)
End Sub
Sub SetPropertyByName(name As String, value As Boolean)
' what should happen here?
End Sub
End Class
Interface ITest
WriteOnly Property SetMe() As Boolean
End Interface
Class TestClass
Implements ITest
Public WriteOnly Property SetMe As Boolean Implements ITest.SetMe
Set(value As Boolean)
Debug.Print("Done")
End Set
End Property
End Class
What should be done in [em]SetPropertyByName[/em] for this to work?
You can call GetMethods() method of your Type instance. This method will return all methods that are available on the type. Including getters and setters for the properties.
Next you need to iterate through the returned array to find the proper MethodInfo for getter or setter.
Getter for property Name is get_Name. Setter is set_Name.