[OT] What are D's values?
Imperatorn
johan_forsberg_86 at hotmail.com
Sat Oct 9 07:31:02 UTC 2021
On Saturday, 9 October 2021 at 06:50:19 UTC, Paulo Pinto wrote:
> On Saturday, 9 October 2021 at 00:59:42 UTC, Greg Strong wrote:
>> [...]
>
> I still find Roslyn compiler plugins and the code generators
> quite good.
>
> You can simulate scope(exit) with an helper struct.
>
> ```csharp
> using System;
>
> #nullable enable
>
> // ensure this is a stack only struct
> ref struct ScopeExit {
> public ScopeExit(Action cleaner)
> {
> this.cleaner = cleaner;
> }
>
> public void Dispose()
> {
> try
> {
> cleaner();
> }
> catch {
> // maybe do something interesting here
> }
> }
>
> private Action cleaner;
>
> }
>
> public class Example {
> public static void Main() {
> using var netSocket = new ScopeExit(() => { /* clean
> somethig */});
> }
> }
> ```
>
> Naturally D's scope(exist) is cleaner to write.
Omg my eyes. Don't rough up C#, use D instead 😅
Maybe like 5% of the C# community even uses structs and of them
0.5% would do ref struct and 0.1% would try to scope guard
something, but nice experiment ofc 💕
More information about the Digitalmars-d
mailing list