どのような状況下でもこれを達成できるでしょうか?
私の現在の状況は次のとおりです。
public class CustomForm : Form
{
public class CustomGUIElement
{
...
public event MouseEventHandler Click;
// etc, and so forth.
...
}
private List<CustomGUIElement> _elements;
...
public void CustomForm_Click(object sender, MouseEventArgs e)
{
// we might want to call one of the _elements[n].Click in here
// but we can't because we aren't in the same class.
}
}
私の最初の考えは、次のような機能を持つことでした。
internal enum GUIElementHandlers { Click, ... }
internal void CustomGUIElement::CallHandler(GUIElementHandler h, object[] args) {
switch (h) {
case Click:
this.Click(this, (EventArgs)args[0]);
break;
... // etc and so forth
}
}
それは恐ろしく醜いクラッジですが、うまくいくはずです...もっとエレガントな解決策があるに違いありませんか? .NET ライブラリは、コントロール内のメッセージ ハンドラーと呼び出しイベントを使用して常にこれを行います。他の誰かが他の/より良いアイデアを持っていますか?