Closed hankovich closed 9 months ago
Not possible. Guid.Empty == default(Guid). StrongId is struct type. So, default(StrongId) where typeof(UNDERLYING) == typeof(Guid) - is also Guid.Empty.
Might be covered in the scope of https://github.com/andrewlock/StronglyTypedId/issues/75. Having the default constructor generation disabled, the developer could just define their own constructor that will disallow Guid.Empty
(or string.Empty
, or 0
).
As Rain0Ash pointed out, this in nice theory, but doesn't really work for structs, because you can always do new MyId()
using the default constructor.
Nevertheless, I'm currently working on a big redesign of the library in this PR:
The main idea is to make the library much more maintainable while also giving people a mechanism to customise the generated IDs as much as they like. So if you want to do something like throw in the constructor when provided Guid.Empty
, you can 🙂
We use guid-backed ids a lot, but since they may represent
Empty
(which it almost never a possible value), we have to do a lot ofchecks. It looks like adding a new backing type (
NotEmptyGuid
) will be handy.Probably we can go even deeper and introduce a new
AllowEmpty
parameter, because empty strings and zero ints/longs are also usually represent invalid identifiers.