generator: fixed Equals/GetHashCode for no fields or padding

Fixed Equals/GetHashCode methods when struct has no fields,
or field is padding.
This commit is contained in:
Stephan Sundermann 2013-05-31 19:38:35 +02:00 committed by Andrés G. Aragoneses
parent c14277f391
commit 115659f46b
2 changed files with 10 additions and 6 deletions

View File

@ -115,12 +115,16 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
sw.WriteLine ("\t\t{");
sw.WriteLine ("\t\t\tbool isEqual = true;");
sb.Append ("this.GetType ().FullName.GetHashCode ()");
foreach (StructField field in fields) {
if (field.IsPadding)
continue;
if (field.IsBitfield) {
if (need_field) {
sw.WriteLine ("\t\tif (!_bitfield{0}.Equals (other._bitfield{0})) return false;", bitfields);
if (sb.Length > 0)
sw.WriteLine ("\t\t\tisEqual &= bitfield{0}.Equals (other._bitfield{0});", bitfields);
//if (sb.Length > 0)
sb.Append (" ^ ");
sb.Append ("_bitfield");
sb.Append (bitfields++);
@ -129,14 +133,14 @@ namespace GtkSharp.Generation {
}
} else {
need_field = true;
sw.WriteLine ("\t\t\tif (!{0}.Equals (other.{0})) return false;", field.EqualityName);
if (sb.Length > 0)
sw.WriteLine ("\t\t\tisEqual &= {0}.Equals (other.{0});", field.EqualityName);
//if (sb.Length > 0)
sb.Append (" ^ ");
sb.Append (field.EqualityName);
sb.Append (".GetHashCode ()");
}
}
sw.WriteLine ("\t\t\treturn true;");
sw.WriteLine ("\t\t\treturn isEqual;");
sw.WriteLine ("\t\t}");
sw.WriteLine ();
sw.WriteLine ("\t\tpublic override bool Equals (object other)");

View File

@ -89,7 +89,7 @@ namespace GtkSharp.Generation {
}
}
bool IsPadding {
public bool IsPadding {
get {
return (CName.StartsWith ("dummy") || CName.StartsWith ("padding"));
}