DIPX: Enum Literals / Implicit Selector Expression

Rumbu rumbu at rumbu.ro
Fri Dec 3 05:41:20 UTC 2021


On Thursday, 2 December 2021 at 19:44:07 UTC, russhy wrote:
> could be implemented if we all agree that it would be a nice 
> addition to the language!
>
> Link: 
> https://gist.github.com/RUSShyTwo/2fcf6d294d25ba748d61927b5eed2944

In C# you can bring all enum members into scope with `using 
static`

```csharp
enum MyEnum {A, B, C}

using static MyEnum;

MyEnum a = A;
```

Usual language overload resolution applies for conflicts. If 
there are conflicts, ambiguity error is rendered by the compiler. 
Even there are conflicts, the compiler is smart enough to know 
when you are referring to `MyEnum` when a variable is typed 
accordingly.

An equivalent D idiom will be

```d
static alias MyEnum;
```

Currently there is a proposal champion for the dot notation also 
in C#, maybe we can learn something: 
https://github.com/dotnet/csharplang/issues/2926




More information about the Digitalmars-d mailing list