标签:des style ar color os 使用 sp java on
示例:
[TestMethod()] public void DeserializeTest() { Person _personA = new Person() { Name = "YanZhiweiA", Age = 10, Address = "shanghaiA" }; Person _personB = new Person() { Name = "YanZhiweiB", Age = 11, Address = "shanghaiB" }; List<Person> _expected = new List<Person>(); _expected.Add(_personA); _expected.Add(_personB); string _jsonString = "[{‘Name‘:‘YanZhiweiA‘,‘Age‘:10,‘Address‘:‘shanghaiA‘},{‘Name‘:‘YanZhiweiB‘,‘Age‘:11,‘Address‘:‘shanghaiB‘}]"; List<Person> _result = (List<Person>)JavaScriptSerializerHelper.Deserialize<Person>(_jsonString); bool _actual = _expected.SequenceEqual(_result, new PersonCompare()); Assert.IsTrue(_actual); }
public class PersonCompare : IEqualityComparer<Person> { public bool Equals(Person x, Person y) { return (x.Age == y.Age) && (x.Address == y.Address) && (x.Name == y.Name); } public int GetHashCode(Person obj) { return obj.Name.GetHashCode(); } }
说明:注意黄色背景部分代码,这样子可以利用SequenceEqual很好比较集合,希望有所帮助,谢谢!
标签:des style ar color os 使用 sp java on
原文地址:http://www.cnblogs.com/Yan-Zhiwei/p/4164890.html