Hacker News new | ask | show | jobs
by _f5ah 1862 days ago
Not sure if it counts, but I made two Roslyn analyzers for C# code. A Roslyn analyzer is basically a C# compiler plugin which can emit additional diagnostics if it encounters a certain pattern in the code being compiled.

One of them lets a developer mark a C# method such that the method must be invoked with named args [1], calling it with positional args is a compile time error then.

And the other makes it a compile time error to discard a marked method's return value [2]. Kind of like it is in functional languages.

Was learning/practicing F# along the way, so the code is probably not so good. But it works :)

[1]: https://github.com/mykolav/require-named-args-fs

[2]: https://github.com/mykolav/must-use-ret-val-fs

1 comments

#1 is awesome! I love the new record syntax for DTOs but I also like using named properties so that the ordering isn’t messed up as they are expanded (but also ensures that every property is filled out, unlike the class initializer syntax). This will be great for enforcing it!