eventflow / EventFlow

Async/await first CQRS+ES and DDD framework for .NET
https://docs.geteventflow.net/
Other
2.36k stars 444 forks source link

ValueObject → record #793

Closed leotsarev closed 3 years ago

leotsarev commented 4 years ago

Hi everyone! C# 9 now introduced record types. I wonder if it's good fit to replace (or at least be supported on par with) for Eventflow.ValueObject Does anyone has in mind what should be done for support of records?

CapitanMurloc commented 3 years ago

Hi @leotsarev,

Example:

public record Address(string Street, string ZipCode);

IComparable interface

Unfortunately, C# records don’t implement the IComparable interface, which means that the following code doesn’t work:

var address1 = new Address("1234 Main St", "20012");
var address2 = new Address("1235 Main St", "20012");
Address[] addresses = new[] { address1, address2 }.OrderBy(x => x).ToArray();

If you try to run it, .NET will throw an exception:

Failed to compare two elements in the array. At least one object must implement IComparable.

C# 9 Records as DDD Value Objects