logoalt Hacker News

Decompiling the New C# 14 field Keyword

51 pointsby ivankahllast Wednesday at 11:54 AM16 commentsview on HN

Comments

Kwpolskatoday at 2:08 PM

> If you want to avoid this issue altogether, consider using a source generator library like Mapster. That way, mapping issues can be caught at build time rather than at runtime.

The only winning move is not to play. Mapping libraries, even with source generators, produce lots of bugs and surprising behavior. Just write mappers by hand.

show 4 replies
drysarttoday at 2:02 PM

All of the caveats basically boil down to "if you need to access the private backing field from anywhere other than the property getter/setter; then be aware it's going to have a funky non C# compliant field name".

In the EF Core and Automapper type of cases, I consider it an anti-pattern that something outside the class is taking a dependency on a private member of the class in the first place, so the compiler is really doing you a favor by hiding away the private backing field more obscurely.

show 2 replies
politelemontoday at 2:27 PM

I can appreciate the steady syntactic sugar that c# has been introducing these past years, they never feel like an abrupt departure from the consistency throughout. I often think that this is what java could have been if it hadn't been mangled by oracle's influence, unfortunately as much I like java it's pretty obvious that different parts have been designed by disjointed committee members focused on just one thing.

show 1 reply
twoodfintoday at 3:11 PM

How does C# the language or C# the language standard evolution process accommodate a new keyword with such a generic name? Is it context-dependent?

show 5 replies