-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making ValueObject.GetEqualityComponents return IComparable is a breaking change #509
Comments
Yes, unfortunately, that's the only way. Otherwise, the comparisons can be inconsistent.
You mean make |
Yes, then an Or is there issues I'm not seeing with |
Yes, that's a good idea. No particular reason why it's not done yet. Appreciate if you could submit a PR. |
PR #510 submitted for getting Entity to implement IComparable. |
Thank you. I'll double check everything this weekend and release a new minor version then. |
Hi, Value Object as an byte arraypublic class FileContent : SimpleValueObject<byte[]>
{
public FileContent(byte[] value) : base(value)
{
}
} Value Object as a List of ValueObjectspublic class Thing: SimpleValueObject<string>
{
public Thing(string value) : base(value)
{
}
}
public class MultpleThings: SimpleValueObject<List<Thing>>
{
public MultpleThings(List<Thing> value) : base(value)
{
}
} Do you have any suggestions how to solve such scenarios? |
You'll need to fall back to the base public class FileContent : ValueObject
{
protected override IEnumerable<IComparable> GetEqualityComponents()
{
yield return Value.GetHashCode();
}
} This would make so you can't really compare two instances of FileContent, but you couldn't do that in the previous version either. Alternatively, if you really want to make this comparison, you can do this: public class FileContent : ValueObject
{
protected override IEnumerable<IComparable> GetEqualityComponents()
{
foreach (byte b in Value)
{
yield return b;
}
}
} But that would most likely make it impractical performance-wise. Same for |
Yeah, we should do that too. Feel free to submit a PR. |
Previously
GetEqualityComponents()
returnedIEnumerable<object>
. Now it returnsIEnumerable<IComparable>
. If the ValueObject holds an Entity and it is used as an Equality Component it causes a compile time error if the Entity doesn't implement IComparable.What is the appropriate fix here? Every type that ValueObject uses as an Equality Component must now implement IComparable? Could this extend to the CSharpFunctionalExtensions Entity type so entities have it is available out-of-the-box?
The text was updated successfully, but these errors were encountered: