RobThree / NUlid

.Net ULID implementation
MIT License
364 stars 25 forks source link

Underlying member variable is reference type? #9

Closed Enver-Yilmaz closed 6 years ago

Enver-Yilmaz commented 6 years ago

Hi,

As I said in the title, a byte array is used as the member variable to hold the value of ULID struct. I (maybe others) expect ULID struct as a value type has a default value without an initialization which should be 00000000-0000-0000-0000-000000000000 in this case. I examine the source of GUID from corefx repo and I saw value types is used for member variables. https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/Guid.cs

I hit this problem when I mess around with ULID and EF Core. EFCore create instances of entities to materialize query results but didn't use constructors and throw null reference exceptions for ULID types used in entity classes.

I changed implementation and use 16 different byte variables instead of byte array and achieve expected behavior (at least by me).

@RobThree Do you consider to change your implementation. I didn't keep my changes but can do it again if you prefer a pull request, because I'm intended to use NUlid on a new project.

RobThree commented 6 years ago

See this commit and 1.3.2 😉