private void RegisterClickLogger(string logTitle)
{
Log log = new Log(logTitle);
{
log.Write("Clicked!");
};
}
As some of you may have discovered through other annoying experiences (like myself :p), Dictionary stores it's values in a structure called KeyValuePair. The key here is that it's a "structure" (a Value Type), not a class (Reference Type). A common issue with this is that it complicates serialization (when using a Reference Type for one of the type parameters). Today, however, the following code through me for a bit of a loop:
foreach (KeyValuePair<string, Type> pair in s_tests)
{
b = new Button();
b.Text = pair.Key;
b.Click += delegate(object sender, EventArgs e)
{
Form f = (Form)Activator.CreateInstance(pair.Value);
f.ShowDialog(this);
f.Dispose();
f = null;
};
b.AutoSize = true;
flow.Controls.Add(b);
}
It seemed all was fine when I clicked the last button, but later when I needed to click one of the earlier buttons I noticed that the same Form was appearing for every button. Looking things over a bit I decided to try changing the code to this:
foreach (KeyValuePair<string, Type> pair in s_tests)
{
b = new Button();
b.Text = pair.Key;
Type t = pair.Value;
b.Click += delegate(object sender, EventArgs e)
{
Form f = (Form)Activator.CreateInstance(t);
f.ShowDialog(this);
f.Dispose();
f = null;
};
b.AutoSize = true;
flow.Controls.Add(b);
}
Alas, there is never enough time and I must run, but I'll be back soon to discuss some developments in my research (as promised),
-TheXenocide