Last active
January 24, 2024 08:45
-
-
Save itn3000/796f8422a0f24c408a4caa9f8888d76a to your computer and use it in GitHub Desktop.
R3 Observable creation on event which requires two arguments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using R3; | |
var a = new A(); | |
using var x1 = Observable.FromEvent<A.PiyoHandler, int>(h => new A.PiyoHandler(h), h => a.PiyoEvent += h, h => a.PiyoEvent -= h) | |
.Subscribe(x => Console.WriteLine($"piyo: {x}")); | |
using var x2 = Observable.FromEventHandler<int>(h => a.MogeEvent += h, h => a.MogeEvent -= h) | |
.Subscribe(x => Console.WriteLine($"moge: {x}")); | |
using var x3 = Observable.FromEvent<A.HogeHandler, (object?, int)>(h => new A.HogeHandler((sender, arg) => h((sender, arg))), h => a.HogeEvent += h, h => a.HogeEvent -= h) | |
.Subscribe(x => Console.WriteLine($"hoge: {x}")); | |
// See https://aka.ms/new-console-template for more information | |
a.X(new object(), 1); | |
class A | |
{ | |
public delegate void HogeHandler(object? sender, int arg); | |
public delegate void PiyoHandler(int arg); | |
public event HogeHandler HogeEvent; | |
public event PiyoHandler PiyoEvent; | |
public event EventHandler<int> MogeEvent; | |
public void X(object? sender, int arg) | |
{ | |
HogeEvent?.Invoke(sender, arg); | |
PiyoEvent?.Invoke(arg); | |
MogeEvent?.Invoke(sender, arg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment