-
Notifications
You must be signed in to change notification settings - Fork 592
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
Map struct to record classes (and structs), use default Equals/GetHas… #2235
Conversation
{ | ||
baseNames.push_back("System.IEquatable<" + name + ">"); | ||
} | ||
_out << nl << "public " << (classMapping ? "sealed partial record class" : "partial record struct") << ' ' << name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is common for record classes and structs to be read-only. However, here they are read-write for backwards source compatibility.
@@ -2235,40 +2229,6 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) | |||
_out << nl << "ice_initialize();"; | |||
_out << eb; | |||
|
|||
if (classMapping) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We get all this (and more) for free from the record class.
@@ -35,7 +19,7 @@ public static void HashCodeAdd<TSource>(ref HashCode hash, IEnumerable<TSource> | |||
} | |||
} | |||
|
|||
public static bool DictionaryEquals(IDictionary d1, IDictionary d2) | |||
internal static bool DictionaryEquals(IDictionary d1, IDictionary d2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is still bogus and used internally. Will cleanup in a follow-up PR.
@@ -28,40 +28,38 @@ private static void allTests(Ice.Communicator communicator) | |||
{ | |||
S2 v; | |||
|
|||
v = def_s2.Clone(); | |||
test(v.Equals(def_s2)); | |||
v = def_s2 with { }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept mostly the same logic in this test. Just cleaned it up.
…hCode
This PR changes the struct-to-C# class mapping: the mapped class is not a (read-write) record class with its default Equals and GetHashCode implementation.
Fixes #2214.