The thing is, for
Set
, you need not just equality but comparison. And you can't really do comparison by reference in .NET. So I think you have 2 choices. 1: Add a Guid to BigType
, fill it with Guid.NewGuid()
when you create a value, and implement a custom comparison on BigType
that compares this Guid. The structural comparison on CollectionType
will use this custom comparison. 2: switch from Set
to Dictionary
, which only needs equality and can be referential, but of course works with mutation so it may not be appropriate in your case.