generator: Add support for suppressing the Equals(T) method in structs
Similarly to what exists for GetHashCode, add a noequals attribute to indicate we don't want the default Equals implementation.
This commit is contained in:
parent
90e834327e
commit
bc498ff650
2 changed files with 10 additions and 6 deletions
1
gapi.xsd
1
gapi.xsd
|
@ -77,6 +77,7 @@
|
||||||
<xs:attribute name="cname" type="xs:string"/>
|
<xs:attribute name="cname" type="xs:string"/>
|
||||||
<xs:attribute name="opaque" type="xs:boolean" use="optional"/>
|
<xs:attribute name="opaque" type="xs:boolean" use="optional"/>
|
||||||
<xs:attribute name="hidden" type="xs:boolean" use="optional"/>
|
<xs:attribute name="hidden" type="xs:boolean" use="optional"/>
|
||||||
|
<xs:attribute name="noequals" type="xs:boolean" use="optional"/>
|
||||||
<xs:attribute name="nohash" type="xs:boolean" use="optional"/>
|
<xs:attribute name="nohash" type="xs:boolean" use="optional"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
|
|
|
@ -123,8 +123,6 @@ namespace GtkSharp.Generation {
|
||||||
StringBuilder hashcode = new StringBuilder ();
|
StringBuilder hashcode = new StringBuilder ();
|
||||||
StringBuilder equals = new StringBuilder ();
|
StringBuilder equals = new StringBuilder ();
|
||||||
|
|
||||||
sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
|
|
||||||
sw.WriteLine ("\t\t{");
|
|
||||||
hashcode.Append ("this.GetType ().FullName.GetHashCode ()");
|
hashcode.Append ("this.GetType ().FullName.GetHashCode ()");
|
||||||
equals.Append ("true");
|
equals.Append ("true");
|
||||||
|
|
||||||
|
@ -156,15 +154,20 @@ namespace GtkSharp.Generation {
|
||||||
hashcode.Append (".GetHashCode ()");
|
hashcode.Append (".GetHashCode ()");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sw.WriteLine ("\t\t\treturn {0};", equals.ToString ());
|
|
||||||
sw.WriteLine ("\t\t}");
|
if (!Elem.GetAttributeAsBoolean ("noequals")) {
|
||||||
sw.WriteLine ();
|
sw.WriteLine ("\t\tpublic bool Equals ({0} other)", Name);
|
||||||
|
sw.WriteLine ("\t\t{");
|
||||||
|
sw.WriteLine ("\t\t\treturn {0};", equals.ToString ());
|
||||||
|
sw.WriteLine ("\t\t}");
|
||||||
|
sw.WriteLine ();
|
||||||
|
}
|
||||||
sw.WriteLine ("\t\tpublic override bool Equals (object other)");
|
sw.WriteLine ("\t\tpublic override bool Equals (object other)");
|
||||||
sw.WriteLine ("\t\t{");
|
sw.WriteLine ("\t\t{");
|
||||||
sw.WriteLine ("\t\t\treturn other is {0} && Equals (({0}) other);", Name);
|
sw.WriteLine ("\t\t\treturn other is {0} && Equals (({0}) other);", Name);
|
||||||
sw.WriteLine ("\t\t}");
|
sw.WriteLine ("\t\t}");
|
||||||
sw.WriteLine ();
|
sw.WriteLine ();
|
||||||
if (Elem.GetAttribute ("nohash") == "true")
|
if (Elem.GetAttributeAsBoolean ("nohash"))
|
||||||
return;
|
return;
|
||||||
sw.WriteLine ("\t\tpublic override int GetHashCode ()");
|
sw.WriteLine ("\t\tpublic override int GetHashCode ()");
|
||||||
sw.WriteLine ("\t\t{");
|
sw.WriteLine ("\t\t{");
|
||||||
|
|
Loading…
Reference in a new issue