From bc498ff65006ccf27db80dcf1f313f60aa22ca36 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Thu, 10 Oct 2013 16:18:36 +0200 Subject: [PATCH] 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. --- gapi.xsd | 1 + generator/StructBase.cs | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gapi.xsd b/gapi.xsd index e0316c19e..7eae62f9a 100644 --- a/gapi.xsd +++ b/gapi.xsd @@ -77,6 +77,7 @@ + diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 9288fc3a4..2953d4709 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -123,8 +123,6 @@ namespace GtkSharp.Generation { StringBuilder hashcode = 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 ()"); equals.Append ("true"); @@ -156,15 +154,20 @@ namespace GtkSharp.Generation { hashcode.Append (".GetHashCode ()"); } } - sw.WriteLine ("\t\t\treturn {0};", equals.ToString ()); - sw.WriteLine ("\t\t}"); - sw.WriteLine (); + + if (!Elem.GetAttributeAsBoolean ("noequals")) { + 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\t{"); sw.WriteLine ("\t\t\treturn other is {0} && Equals (({0}) other);", Name); sw.WriteLine ("\t\t}"); sw.WriteLine (); - if (Elem.GetAttribute ("nohash") == "true") + if (Elem.GetAttributeAsBoolean ("nohash")) return; sw.WriteLine ("\t\tpublic override int GetHashCode ()"); sw.WriteLine ("\t\t{");