我有这个 C# 类
public class EntryClass
{
public string Field { get; set; }
public List<FieldKeyValuePair<string, string>> FieldKeyValPairs { get; set; }
public bool Equals(EntryClass other)
{
return Field.Equals(other.Field)
&& FieldKeyValPairs.Equals(other.FieldKeyValPairs);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((EntryClass)obj);
}
}
public class FieldKeyValuePair<K, V>
{
public K Key { get; set; }
public V Value { get; set; }
public bool Equals(FieldKeyValuePair<K, V> other)
{
return Key.Equals(other.Key)
&& Value.Equals(other.Value);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((FieldKeyValuePair<K, V>)obj);
}
}
尝试做Assert.IsTrue(expected.SequenceEqual(actual));
总是给我错误,我看到即使预期和实际具有相同的 FieldKeyValPairs 这个表达式总是命中错误 && FieldKeyValPairs.Equals(other.FieldKeyValPairs);
编辑 并且预期和实际是类型
List<EntryClass> expected = new List<EntryClass>(); // TODO:
List<EntryClass> actual = new List<EntryClass>();