ReactiveUI 的最小可运行示例 - 未运行 [英] Minimum runnable example for ReactiveUI - not running

查看:45
本文介绍了ReactiveUI 的最小可运行示例 - 未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的 ReactiveUI 问题生成一个 MWE.但是我遇到了新问题.

I wanted to generate a MWE for my ReactiveUI problem. However I came across new problems.

这是我试过的:

using System;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

namespace ReactivUI_Test
{
    class BarClass : ReactiveObject
    {
        [Reactive] public String Baz { get; set; } = "";
        public BarClass(String b) { Baz = b; }
        public BarClass() { Baz = "!!!"; }
        public override String ToString() { return Baz.ToString(); }
    }



    class FooClass : ReactiveObject
    {
        [Reactive] public BarClass Bar { get; set; } = new BarClass();
        public override String ToString() { return Bar.ToString(); }
    }


    class ViewModel: ReactiveObject
    {
        [Reactive] FooClass Foo { get; set; } = new FooClass();

        public ViewModel()
        {
            this.WhenAnyValue(x => x.Foo.Bar.Baz)
                 .Subscribe(x => Console.WriteLine("Hallo " + x?.ToString()));          // <- Runtime Error in this line

            Console.WriteLine("Example 1");
            this.Foo.Bar.Baz = null;
            Console.WriteLine("Example 2a");
            this.Foo.Bar = new BarClass();
            Console.WriteLine("Example 2b");
            this.Foo.Bar = new BarClass();
            Console.WriteLine("Example 3");
            this.Foo.Bar = new BarClass() { Baz = "Something" };

            Console.WriteLine("Example 4");
            this.Foo = new FooClass() ;

            Console.WriteLine("Finish");
            Console.ReadLine();
        }
    }


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

我得到的运行时错误是:

The runtime error I get is:

TypeLoadException: Typ 的方法GetActivationForView""ReactiveUI.ActivationForViewFetcher" der Assembly "ReactiveUI.WPF,版本=9.11.0.0,文化=中性,PublicKeyToken=null"没有实施.

TypeLoadException: The method "GetActivationForView" of Typ "ReactiveUI.ActivationForViewFetcher" der Assembly "ReactiveUI.WPF, Version=9.11.0.0, Culture=neutral, PublicKeyToken=null" has no Implementation.

推荐答案

找到解决方案:

Nuget 数据包:未安装 ReactiveUI.WPF.

Nuget packet: ReactiveUI.WPF was not installed.

现在作为纯控制台应用程序工作.

Now working as pure console application.

输出:

Hallo !!!
Example 1
Hallo
Example 2a
Hallo !!!
Example 2b
Example 3
Hallo Something
Example 4
Hallo !!!

这篇关于ReactiveUI 的最小可运行示例 - 未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆