mercredi 14 décembre 2016

VB.net: Extending Reflection To Accept Special Property Attributes

OK, so I have a custom control that I have been working on for a while that I have tricked out to have all sorts of special features and options. I have given the end user the ability to make the control act and look very diversely by simply toggling a few properties. Now, the only problem is that the control is so complex that I feel the need to create an example program (and maybe a tutorial video) that uses said control. During learning, the user COULD run the program with certain setting on the control, see if the control acts like expected (or as needed), stop the program, repeat and rinse. This learning process, however, would likely take longer than I would like.

This brings me to the fact that I am just learning about reflection right now. I see how using reflection I could expose all of these properties to allow the user to change these values at runtime and greatly speed up the learning process. This would also be a great project for me to master reflection through. The problem is, there are SO MANY properties that a new user would have NO idea which ones to try out or how they would work. This brings me to how you might be able to help.

So, I understand that when using reflection you can use flags to pare down the properties that are returned. However, using said flags either leave me with no options, still far too many, or the wrong ones (and I do not wish to hard code the appropriate properties into a combobox if possible, as this would not be manageable as I add more functionality). My idea is to create an attribute to place on the properties that I want to expose to the user at runtime that will correspond to a new flag I would make for the GetProperties() method (I guess through an extension?).

My questions are…

1) Is this doable? Or maybe is there an easier way that I am thinking?

2) Can anyone point me to an example where this has already been done, give me a detailed outline of what I would need to do, or point me to a comprehensive document that talks about all these topics in conjunction.

Note1: Please no low effort answers telling me to google it, or with little more than links to the msdn pages on reflection, attributes, and extensions… yes, I already know they are there, but you CAN include them in a comprehensive answer).

Note2: if you include code I would prefer VB.net, but I understand C# almost as well.





Aucun commentaire:

Enregistrer un commentaire