c# - Overloading == operator for class containing only string attributes -
What would be the best (the most elegant or performing) way to overload the parity operator on a class with the same string attribute?
Example:
Class MagicClass {public string first attribute {get; Set; } Public String II rating {get; Set; } Public string third contribution {get; Set; } Public String Fourth Feature {get; Set; } Public string fifth attribute {get; Set; }}
I know how to overload the operator, however, I am thinking of the following points:
- Is this the way
About something like this, just create an array of properties and a loop.
Internal class MagicClass {public string first attribute {get; Set;} public string second entry {get; Set;} public strings third unbreakable {get; Set;} Public String Fourth Feature {get; Set;} public string fifth attribute {get; Set;} Personal string [AllProperties // array of all properties {get {return new [] {first attribute, second property, third contribution, fourth attribute, fifth attribute}; }} Protected bow par (magicclass other) {var thisProps = this.AllProperties; Var other whites = other.AllProperties; Return this form. Whites (other purses); } Public override bool par (object obez) {if (rectified (empty, obg)) returned false; If (referenced (this, OBJ)) is true; If (obj.GetType ()! = This.GetType ()) false return; Return par (magic class) oz); } Public override intoshosh () {unchecked {var thisProps = this.AllProperties; Int Hashod = 0; Foreign (Pro prop in this prop) {hashcode = (hashode * 397) ^ (prop! = Null? Prop.getHashCode (): 0); } Return Hashdod; }}}
Then you can call the similar
method in your operator overload. If you are lazy to create the AllProperties
array, you can use the reflection
, but the IMO reflection is overkill here.
Comments
Post a Comment