public class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.Test();
Console.ReadLine();
} public void Test()
{
List<People> initPeopleList = new List<People>();
People people = new People("Richy",25,"Shanghai");
initPeopleList.Add(people);
people = new People("Sherry",25,"Shanghai");
initPeopleList.Add(people); List<People> newPeopleList = new List<People>();
people = new People("Kim",25,"Shanghai");
newPeopleList.Add(people);
if (CompareEntity(initPeopleList, newPeopleList))
{
Console.WriteLine("The two entity has some field is not equal.");
}
else
{
Console.WriteLine("The two entity are the same.");
}
}
public bool CompareEntity(List<People> initPeopleList,List<People> newPeopleList)
{
bool DiffFlag = false;
if (initPeopleList != null && newPeopleList != null)
{
List<PropertyInfo> infoList = typeof(People).GetProperties().ToList();
foreach (var initPeople in initPeopleList)
{
var commonList = newPeopleList.Where(s => (s.Id == initPeople.Id)).FirstOrDefault(); //We assume id is the primary key.
if (commonList != null)
{
foreach (var propertyInfo in infoList)
{
var initValue = initPeople.GetType().GetProperty(propertyInfo.Name).GetValue(initPeople, null);
var newValue = commonList.GetType().GetProperty(propertyInfo.Name).GetValue(commonList, null);
if (initValue != null && !initValue.Equals(newValue))
{
DiffFlag = true;
break;
}
}
}
else
{
DiffFlag = true;
break;
}
}
}
else if((initPeopleList == null || newPeopleList == null) && (initPeopleList!=newPeopleList))
{
DiffFlag=true;
} return DiffFlag;
} } public class People
{
public string EnglishName { get; set; }
public int Id { get; set; }
public string Address { get; set; } public People(string name, int Id, string address)
{
this.EnglishName = name;
this.Id = Id;
this.Address = address;
}
}

  

最新文章

  1. C#编程总结(二)多线程基础
  2. go语言 类型:数组
  3. 北大poj-1062
  4. Pattern Lab - 构建先进的原子设计系统
  5. https://github.com/oneuijs/You-Dont-Need-jQuery
  6. Openjudge计算概论-单词翻转
  7. TASK_INTERRUPTIBLE 和TASK_UNINTERRUPTIBLE
  8. WPF 中,如何使用自定义的resources
  9. ria service 单元测试
  10. Java 中 Vector、ArrayList、List 使用深入剖析【转载】
  11. URAL 1963 Kite 四边形求对称轴数
  12. Block 实现 浅析
  13. python 使用 &#39;python -m pip install --upgrade pip&#39;提示PermissionError: [WinError 5] 拒绝访问
  14. [[NSBundle mainBundle] pathForResource:fileName ofType:]获取文件路径不成功
  15. 【BZOJ1040】【ZJOI2008】骑士
  16. [转]C# 4.7.2 安装
  17. halcon 动态阈值分割之偏移值
  18. 2018-2019-2 网络对抗技术 20165212 Exp4 恶意代码分析
  19. .NET Core容器化之多容器应用部署-使用Docker-Compose
  20. mysql 设置默认时间为now()

热门文章

  1. mysql 简单游标
  2. Python中的isinstance函数
  3. Visual Studio 2013使用SASS和Compass--SASS和Compass安装
  4. 转:批处理for命令详解
  5. 利用 Android Studio 和 Gradle 打包多版本APK
  6. HDU 5724 Chess(博弈论)
  7. 1.2UISwitch 1.3 自定义UIswitch 1.4pickerView
  8. 揭秘Amazon反应速度超快的下拉菜单
  9. JavaWeb学习过程 之c3p0的使用
  10. Problem C Andy&#39;s First Dictionary(set的使用)