Reflection & GetProperty

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 always used interfaces when going across app domains. You can search the forum for “code donation” to find the open source version of Tinkr.

Can you please elaborate on that? How do you use Reflection to access Properties? How does Interfaces fit into this process?

Btw, Tinkr is placed here: GitHub - osre77/Tinkr: Tinkr provides a comprehensive set of GUI controls that allow you to quickly develop graphic applications for NETMF devices with natively supported screens as well as support for the new Skewworks Image32 and multiple application standards! The initial code of Tinkr v2.5.0 was donated by Skewworks (www.Skewworks.com).

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?

@ iamin

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.

2 Likes

Thank you 100 times! :dance:

You are welcome! :slight_smile: