You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
イベント駆動なアプリを開発する際に必要なイベントハンドラの追加について、どのように実装するか考える。
最終的には
button.Click.Add()
にクロージャを渡してイベントを追加したい。※関数ポインタを渡すのは別途考える
-> 因みにC#と違ってクラス配下に関数があるわけではないし、イベントハンドラに構造体のメソッドは渡せないので、コントロール(Buttonコントロール等)をグローバル変数に配置することになるが、モジュール分割により直観的に書けるのではないかと思っている。一旦、クロージャ/関数のシグネチャは無視して考える。
C#では
Click
はControl
クラスのevent
として定義されている。この時、
+=
でイベントハンドラを追加する(button.Control += () => {}
)と、内部でadd_Click
が呼ばれる。Click
内部のadd {}
ではEventHandlerlist
型のEvents
というプロパティをget
して、Events.AddHandler(EventClick, value);
でイベントハンドラを登録している。こうなるとこの処理を直接呼びたくなるが、
Events
はprotected
なため、外部からアクセスできない。よって、「
System.Windows.Forms.dll
」を使いまわす場合、どうにかしてSystem.EventHandler
を渡してadd_Click
を呼ぶしかない。自動プロパティみたいに
add;
を宣言して、+=
で呼び出した時にadd_Click
を呼び出すようにしよう。trait
を実装した後に、EventHandler
に対してIEvent
インターフェース的なのを実装して、Add
で呼び出せるように出来るかな 🤔そして、c#では
delegate
として宣言されているEventHandler
だが、ilではclass
として呼び出している。関数ポインタをロードして、
EventHandler
クラスを初期化している。シグネチャは一旦無視して考えるので、クロージャを渡したら
EventHandler
型になるようにする???Beta Was this translation helpful? Give feedback.
All reactions