this.value1
c.value1
両方ともnullまたは非nullのいずれかになります。したがって、合計4つの組み合わせをテストします。value2
nullまたは非nullにすることもできます。
以下のif-then-elseは、三項演算子を使用する(if then else演算子を使用する? :
)などの短いものに置き換えることができますか?との4つの組み合わせをテストしているため、この特定のケースでは悪い習慣にvalue1
なりvalue2
ますか?
public override bool Equals(object obj)
{
bool value1_check = false;
bool value2_check = false;
var c = obj as ObjectType;
if (this.value1 != null)
value1_check = this.value1.Equals(c.value1);
else if ((this.value1 == null) && (c.value1 == null))
value1_check = true;
else if ((this.value1 == null) && (c.value1 != null))
value1_check = c.value1.Equals(this.value1);
if (this.value2 != null)
value2_check = this.value2.Equals(c.value2);
else if ((this.value2 == null) && (c.value2 == null))
value2_check = true;
else if ((this.value2 == null) && (c.value2 != null))
value2_check = c.value2.Equals(this.value2);
return (value1_check && value2_check);
}