C# .NET Rx- Where is System.Reactive?

前端 未结 2 781
梦毁少年i
梦毁少年i 2021-02-03 21:00

I have an intensive Java background so forgive me if I\'m overlooking something obvious in C#, but my research is getting me nowhere. I am trying to use the reactive Rx .NET lib

相关标签:
2条回答
  • 2021-02-03 21:39

    As of version 3, the Rx project is now known as System.Reactive because it "brings the NuGet package naming in line with NuGet guidelines and also the dominant namespace in each package."

    It can be downloaded from NuGet by searching for "System.Reactive" or you can download it here: https://www.nuget.org/packages/System.Reactive/

    Here is the project's GitHub page: https://github.com/Reactive-Extensions/Rx.NET

    Package Mappings

    • Rx-Main System.Reactive
    • Rx-Core System.Reactive.Core
    • Rx-Interfaces System.Reactive.Interfaces
    • Rx-Linq System.Reactive.Linq
    • Rx-PlatformServices System.Reactive.PlatformServices
    • Rx-Testing Microsoft.Reactive.Testing

    Source

    0 讨论(0)
  • 2021-02-03 21:51

    You have probably not added the necessary assembly references for Rx to your project. (Referencing an assembly is not the same thing as importing a namespace! You already know what a namespace is; an assembly is something similar to a JAR; the smallest unit of code deployment/distribution. Your project must reference it before the namespaces defined inside it become available for use.)

    The compiler likely doesn't complain about IObservable<T> and IObserver<T> because your project is targeting .NET Framework version 4 or later. These two interfaces have been part of the core .NET Framework Class Library (FCL) since .NET version 4. (If you targeted an earlier .NET version, you'd get errors for using these undefined interfaces, too.)

    Every part of Rx other than these two interfaces is not included in the core .NET FCL, but resides in their own (add-on) assemblies. You can add them to your project e.g. by installing the corresponding NuGet packages:

    1. In Visual Studio, go to ToolsNuGet Package ManagerPackage Manager Console.

    2. In the NuGet console window, select the target project (where you want to use Rx) in the drop-down list Default project.

    3. Next, type Install-Package System.Reactive and hit Enter ↵. (Note: This package used to be called Rx-Main previously; see this answer for details.)

    4. This will add the System.Reactive.* assembly references to your project.

    0 讨论(0)
提交回复
热议问题