ITADN

Discussion: Lightweight nominal primitive types (newtype) for stronger ID safety

#9995ClosedJavadSayedi 创建于 2026-02-14
J
JavadSayedicommented
I would like to start a discussion about introducing lightweight nominal primitive types (newtype) in C#. The goal is to provide compile-time distinction between identifier types (e.g., OrderId, OrderItemId) while preserving the underlying runtime representation and performance characteristics. This feature aims to eliminate a common class of enterprise bugs caused by accidental assignment between different ID types sharing the same primitive (int, Guid, etc.). A full draft proposal has been prepared and can be submitted as a formal PR if there is interest from the language design team. I would appreciate feedback on whether this direction aligns with C# design principles. [lightweight-nominal-primitive-types-proposal.md](https://github.com/user-attachments/files/25314185/lightweight-nominal-primitive-types-proposal.md)
关闭于 2026-02-14 1 条评论