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:
parent
c14277f391
commit
115659f46b
2 changed files with 10 additions and 6 deletions
|
@ -115,12 +115,16 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
|
sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
|
||||||
sw.WriteLine ("\t\t{");
|
sw.WriteLine ("\t\t{");
|
||||||
|
sw.WriteLine ("\t\t\tbool isEqual = true;");
|
||||||
|
sb.Append ("this.GetType ().FullName.GetHashCode ()");
|
||||||
|
|
||||||
foreach (StructField field in fields) {
|
foreach (StructField field in fields) {
|
||||||
|
if (field.IsPadding)
|
||||||
|
continue;
|
||||||
if (field.IsBitfield) {
|
if (field.IsBitfield) {
|
||||||
if (need_field) {
|
if (need_field) {
|
||||||
sw.WriteLine ("\t\tif (!_bitfield{0}.Equals (other._bitfield{0})) return false;", bitfields);
|
sw.WriteLine ("\t\t\tisEqual &= bitfield{0}.Equals (other._bitfield{0});", bitfields);
|
||||||
if (sb.Length > 0)
|
//if (sb.Length > 0)
|
||||||
sb.Append (" ^ ");
|
sb.Append (" ^ ");
|
||||||
sb.Append ("_bitfield");
|
sb.Append ("_bitfield");
|
||||||
sb.Append (bitfields++);
|
sb.Append (bitfields++);
|
||||||
|
@ -129,14 +133,14 @@ namespace GtkSharp.Generation {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
need_field = true;
|
need_field = true;
|
||||||
sw.WriteLine ("\t\t\tif (!{0}.Equals (other.{0})) return false;", field.EqualityName);
|
sw.WriteLine ("\t\t\tisEqual &= {0}.Equals (other.{0});", field.EqualityName);
|
||||||
if (sb.Length > 0)
|
//if (sb.Length > 0)
|
||||||
sb.Append (" ^ ");
|
sb.Append (" ^ ");
|
||||||
sb.Append (field.EqualityName);
|
sb.Append (field.EqualityName);
|
||||||
sb.Append (".GetHashCode ()");
|
sb.Append (".GetHashCode ()");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sw.WriteLine ("\t\t\treturn true;");
|
sw.WriteLine ("\t\t\treturn isEqual;");
|
||||||
sw.WriteLine ("\t\t}");
|
sw.WriteLine ("\t\t}");
|
||||||
sw.WriteLine ();
|
sw.WriteLine ();
|
||||||
sw.WriteLine ("\t\tpublic override bool Equals (object other)");
|
sw.WriteLine ("\t\tpublic override bool Equals (object other)");
|
||||||
|
|
|
@ -89,7 +89,7 @@ namespace GtkSharp.Generation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsPadding {
|
public bool IsPadding {
|
||||||
get {
|
get {
|
||||||
return (CName.StartsWith ("dummy") || CName.StartsWith ("padding"));
|
return (CName.StartsWith ("dummy") || CName.StartsWith ("padding"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue