It's easy to obtain the values for the properties and fields or invoke methods but it has been difficult for me to display the Event handlers. I can't just use a GetValue function like I can for PropertyInfo.
I have tried following the instructions from https://web.archive.org/web/20131213074318/http://bobpowell.net/eventsubscribers.aspx - this works to display the events in Windows Forms.
However, this will not work for Silverlight because Silverlight does not have a 'EVENTHANDERLIST'.
Any ideas for how I can display the event VALUES in Silverlight?
I have tried this
namespace eventhandlers
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Type t = sender.GetType();
FieldInfo fi = t.GetFields(BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic);
EventHandler eh = (EventHandler)fi.GetValue(sender);
System.Reflection.EventInfo[] eventInfo = button1.GetType().GetEvents();
Delegate[] dels = eh.GetInvocationList();
foreach(Delegate del in eh.GetInvocationList() )
{
string text = del.Method.Name;
textBlock1.Text = text + ". " + textBlock1.Text;
}
}
}
}
But I get the error "FieldAccessException was unhandled by user code' and ''SilverlightApp1.MainPage.button1_Click (System.Object, System.Windows.RoutedEventArgs)' method 'System.Windows.Controls.Primitives.ButtonBase._isLoaded' failed to access the field." at
EventHandler eh = (EventHandler)fi.GetValue(sender);