You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While experimenting with Generator.Equals, I found that if I try to customize string equality to be case insensitive for a property that is for example an array of strings, the code generated by Generator.Equals will currently incorrectly assume the property is a string. GetHashCode code produces a compilation error:
CS0411: The type arguments for method 'HashCode.Add(T, IEqualityComparer?)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
I assume the only way Generator.Equals can handle this case is via a custom equality, but I believe the case to be common enough to consider supporting it directly. Making StringEqualityAttribute handle it seems like it would be nice. Other than that, in general it would be nice if generation failed with a better error when an attribute is used with a member of an unsupported type.
Moreover, if I try to combine StringEqualityAttribute and UnorderedEqualityAttribute on the same property, generation will obey unordered equality and the intent to treat the string elements as case insensitive will be ignored. Personally I think this is also a compelling scenario to support.
Generator.Equals will detect the attribute and generate code that assumes that the property is a string, for both the code generated for equality and the code generated for hash code:
The library is not very smart at detecting when the wrong attributes are used. You should be able to roll your own comparer for string collections and use it with the CustomEquality attribute. There are examples of CustomEquality in the README.
One way to potentially support this scenario is to extend the collection comparers to take an item comparer as an optional argument.
While experimenting with Generator.Equals, I found that if I try to customize string equality to be case insensitive for a property that is for example an array of strings, the code generated by Generator.Equals will currently incorrectly assume the property is a string. GetHashCode code produces a compilation error:
I assume the only way Generator.Equals can handle this case is via a custom equality, but I believe the case to be common enough to consider supporting it directly. Making StringEqualityAttribute handle it seems like it would be nice. Other than that, in general it would be nice if generation failed with a better error when an attribute is used with a member of an unsupported type.
Moreover, if I try to combine StringEqualityAttribute and UnorderedEqualityAttribute on the same property, generation will obey unordered equality and the intent to treat the string elements as case insensitive will be ignored. Personally I think this is also a compelling scenario to support.
Repro
Generator.Equals will detect the attribute and generate code that assumes that the property is a string, for both the code generated for equality and the code generated for hash code:
The text was updated successfully, but these errors were encountered: