1

I'm using MediatR alongside ReactiveUI - and both of them have the Unit type, and seems like they don't like each other:

Everytime both namespace are imported (MediatR and System.Reactive), I need to use using to distinguish between them two (normally Unit from System.Reactive is used - since it's baked into ReactiveUI)

May I know, is there any approach other than this (and inserting fully qualified name, which is kinda verbose)?

using MediatR;
using System.Reactive;
using Unit = System.Reactive.Unit;


// ...
Unit a;
// or  System.Reactive.Unit a;

language-ext also has its own Unit type... Is there any project that aims to unify the Unit type in .NET?

GaryNg
  • 1,103
  • 9
  • 16
  • Don't use MediatR ;) or ReactiveUI, your choice ;) – Fabio Nov 22 '19 at 01:53
  • @Fabio but... but... I have to use them together... – GaryNg Nov 22 '19 at 01:54
  • 2
    It's an interesting question given the context but it's ultimately about names[paces]. Maybe the best, and worst, solution is to define your own `Unit` with implicit operators to and fro the various other types. – ChiefTwoPencils Nov 22 '19 at 02:07
  • 1
    I think the solution you have is the cleanest available. Others would be to do fully qualified at the time of using the Unit type. – Glenn Watson Nov 22 '19 at 10:53
  • 1
    If you use ChiefTwoPencils solution consider naming it different so you don't have the conflict in names still. Eg you can use the implicit conversions then – Glenn Watson Nov 22 '19 at 10:54
  • @GlennWatson I am thinking of naming it `Void`, any suggestions for better name? – GaryNg Nov 22 '19 at 12:51
  • 1
    There's already a type `System.Void`, that is never used in C#, so probably a bad choice: https://learn.microsoft.com/en-us/dotnet/api/system.void?view=netframework-4.8 – Shlomo Nov 22 '19 at 15:37
  • I would recommend nicknames: `using RxUnit = System.Reactive.Unit;` and `using MrUnit = MediatR.Unit`. – Shlomo Nov 22 '19 at 15:38
  • @Shlomo yes... I just realized that.... Seems like there is no better choice other than `Unit` and `Void`? For sake of consistency, I would rather use one instead of using nicknames to differentiate between them two though. – GaryNg Nov 23 '19 at 03:32
  • 3
    I use `LanguageExt.Unit` (https://github.com/louthy/language-ext) a lot and besides having incompatible `System.Reactive.Unit` there is another -- IMHO bigger compatibility annoyance: There is `void` (and `Action`) built-in in C# which ideally would be replaced by some `Unit` type, too. Unit should be a language feature built-in. Please go to https://github.com/dotnet/csharplang/issues/1604 and add your comment / vote for comment / subscribe. – stb Nov 25 '19 at 15:32

0 Answers0