public List <string> CompareWith(PlayerGameItem that) { List <string> differents = ObjectUtil.CompareObjects(this, that); differents.AddRange(ObjectUtil.CompareObjects(this.Attrs, that.Attrs)); if (CompareLists(this.Children, that.Children) != 0) { //Children are different differents.Add("Children"); } if (CompareLists(this.Equipments, that.Equipments) != 0) { //Equipments are different differents.Add("Equipments"); } List <string> differentsProps = this.ExtraProps.CompareWith(that.ExtraProps); if (differentsProps.Count > 0) { //Add the ExtraProps property name differents.Add("ExtraProps"); //And add the difference inside ExtraProps differents.AddRange(differentsProps); } return(differents); }
private int CompareVariableLists <T, M>(List <T> thisChildren, List <T> thatChildren) where T : Variable <M> { //Check whether the List is empty if (thisChildren == null || thisChildren.Count == 0) { if (thatChildren == null || thatChildren.Count == 0) { return(0); } else { return(-1); } } if (thatChildren == null || thatChildren.Count == 0) { return(1); } //Check the list size if (thisChildren.Count > thatChildren.Count) { return(1); } else if (thisChildren.Count < thatChildren.Count) { return(-1); } //Sort the list to ease the compare thisChildren.Sort((x, y) => x.Tag.CompareTo(y.Tag)); thatChildren.Sort((x, y) => x.Tag.CompareTo(y.Tag)); for (int i = 0; i < thisChildren.Count; i++) { List <string> differents = ObjectUtil.CompareObjects(thisChildren[i], thatChildren[i]); if (differents != null && differents.Count > 0) { //Found different //But cannot describe the bigger or smaller in the list, always return 1 for different return(1); } } //No difference return(0); }