public int CompareTo(object obj) { ComparableAddress other = obj as ComparableAddress; if (other == null) { return(-1); } if (this.IsIP) { if (other.IsIP) { byte[] thisBytes = this.addressIP.GetAddressBytes(); byte[] otherBytes = other.addressIP.GetAddressBytes(); if (thisBytes.Length != otherBytes.Length) // IPv6 address are deemed to come first { return(otherBytes.Length - thisBytes.Length); } for (int i = 0; i < thisBytes.Length; ++i) { if (thisBytes[i] != otherBytes[i]) { return((int)thisBytes[i] - (int)otherBytes[i]); } } return(0); } else { return(-1); } } else if (this.IsPartialIP) { if (other.IsIP) { return(1); } else if (other.IsPartialIP) { return(StringUtility.NaturalCompare(this.partialIP.ToString(), other.partialIP.ToString())); } else { return(-1); } } else { if (other.IsIP || other.IsPartialIP) { return(1); } else { return(addressString.CompareTo(other.addressString)); } } }