kswoll / ReactiveUI.Fody

C# Fody extension to generate RaisePropertyChange notifications for properties and ObservableAsPropertyHelper properties.
MIT License
154 stars 31 forks source link

Reactive attribute doesn't appear to function #1

Closed jcmm33 closed 9 years ago

jcmm33 commented 9 years ago

I'm done a small test console application which compiles correctly (after changing the assembly name for the net45 build for the fodyhelper) but I don't appear to be seeing property values changing.

Simple app :

class Program
{
    public class ViewModel:ReactiveObject
    {
        [Reactive] public int Value1 { get; set; }

        private int _value2;

        public int Value2 { get { return _value2; } set { this.RaiseAndSetIfChanged(ref _value2, value); } }
    }

    public class View : ReactiveObject
    {
        private readonly ViewModel _model;

        public View(ViewModel model)
        {
            _model = model;

            this.WhenAnyValue(m => m._model.Value1).Subscribe(x => Console.WriteLine("value1 ={0}", x));
            this.WhenAnyValue(m => m._model.Value2).Subscribe(x => Console.WriteLine("value2 ={0}", x));
        }
    }

    static void Main(string[] args)
    {
        ViewModel vm = new ViewModel();

        View v = new View(vm);

        vm.Value1 = 2;
        vm.Value2 = 2;

        vm.Value1 = 3;
        vm.Value2 = 3;

        Console.ReadLine();
    }
}

Which produces the output : value1 =0 value2 =0 value2 =2 value2 =3

which is clearly not right.

kswoll commented 9 years ago

It sounds like the weaver isn't kicking in. Can you change your build verbosity (Tools | Options | Projects and Solutions | Build and Run | MSBuild project build output verbosity) to "diagnostic", rebuild your project, and then attach the entire log file here? Alternatively, if you zip up your sample project, I'd be happy to take a look at it on my side. There could be a variety of potential reasons in terms of project setup that could cause this plugin to not activate. Thanks!

jcmm33 commented 9 years ago

Log file is here : http://1drv.ms/1FAdQ27

As I said I did have to change the name of the assembly and remove the .net45 otherwise the 'weaving' wouldn't execute and generated an error.

kswoll commented 9 years ago

Hmm, it's definitely activating the reactiveui.fody plugin. I'll try to create your console app from scratch and see if I can repro. Admitedly I had been donig most of my testing in Xamarin.Ios. If I can't repro, I'll hit you up for that zip file, but let me get back to you first.

jcmm33 commented 9 years ago

The application project is here http://1drv.ms/1bYU30S

jcmm33 commented 9 years ago

On this subject, I'm looking to use in a PCL which targets both Xamarin & WP8.1/WinRT . Currently the package won't install within a PCL targeting the above.

kswoll commented 9 years ago

Hey, thanks again for reporting this. The bug was due to the embarassing fact that I was neglecting to account for nested types. The latest version in nuget should fix this bug for you. I'm going to go ahead and close out this issue and create a new one (https://github.com/kswoll/ReactiveUI.Fody/issues/2) for the PCL problem. (I'll investigate that one next)