Quantcast
Channel: Silverlight 5 forum
Viewing all articles
Browse latest Browse all 1083

How use Reflection to display Event Handlers?

$
0
0

I'm aware that to display the Control properties, you just need to use a code like this

System.Reflection.PropertyInfo[] propertyInfo = checkBox1.GetType().GetProperties();

for (int i = 0; i < propertyInfo.Length; i++)
{
     textBlock.Text = i + " " + propertyInfo[i].Name + "\n" + textBlock.Text;
};

You can also get the names of the Events like this

System.Reflection.EventInfo[] eventInfo = checkBox1.GetType().GetEvents();
for (int i = 0; i < eventInfo.Length; i++)
{
       textBlock.Text = eventInfo[i].Name + "\n" + textBlock.Text;
};

But how about to display the Event handlers? I can't just use a GetValue function like I can for propertyInfo

propertyInfo[i].GetValue(checkBox1, null)


If I try below, I can the error "System.Reflection.EventInfo does not contain a definition for GetValue"

eventInfo[i].GetValue(checkBox1, null)


Viewing all articles
Browse latest Browse all 1083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>