コード例 #1
0
        public void Generate()
        {
            var    clickEvent   = typeof(EventAsObservableGeneratorSampleClass).GetEvents().Single(e => e.Name == "Click");
            var    code         = EventAsObservableGenerator.GenerateExtensionMethodOfEvent(clickEvent);
            string expectedCode =
                @"public static IObservable<EventPattern<EventArgs>> ClickAsObservable(this EventAsObservableGeneratorSampleClass @this)
{
    return Observable.FromEventPattern<EventHandler, EventArgs>(
        h => @this.Click += h, 
        h => @this.Click -= h);
}";

            Assert.AreEqual(expectedCode, code);
        }
コード例 #2
0
        public void GeneratePrimitive()
        {
            var    clickEvent   = typeof(EventAsObservableGeneratorSampleClass).GetEvents().Single(e => e.Name == "GenericPrimitiveEvent");
            var    code         = EventAsObservableGenerator.GenerateExtensionMethodOfEvent(clickEvent);
            string expectedCode =
                @"public static IObservable<EventPattern<int>> GenericPrimitiveEventAsObservable(this EventAsObservableGeneratorSampleClass @this)
{
    return Observable.FromEventPattern<EventHandler<int>, int>(
        h => @this.GenericPrimitiveEvent += h, 
        h => @this.GenericPrimitiveEvent -= h);
}";

            Assert.AreEqual(expectedCode, code);
        }