แก้ไฟล์ build
This commit is contained in:
parent
9fb82fb45a
commit
d6573a6d0c
15 changed files with 1676 additions and 374 deletions
51
Extensions/ObjectExtension.cs
Normal file
51
Extensions/ObjectExtension.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BMA.EHR.Organization.Service.Extensions
|
||||
{
|
||||
public static class ObjectExtension
|
||||
{
|
||||
public static bool DeepCompare(this object obj, object another)
|
||||
{
|
||||
if (ReferenceEquals(obj, another)) return true;
|
||||
if ((obj == null) || (another == null)) return false;
|
||||
//Compare two object's class, return false if they are difference
|
||||
if (obj.GetType() != another.GetType()) return false;
|
||||
|
||||
var result = true;
|
||||
//Get all properties of obj
|
||||
//And compare each other
|
||||
foreach (var property in obj.GetType().GetProperties())
|
||||
{
|
||||
var objValue = property.GetValue(obj);
|
||||
var anotherValue = property.GetValue(another);
|
||||
if (!objValue.Equals(anotherValue)) result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool Compare(this object obj, object another)
|
||||
{
|
||||
if (ReferenceEquals(obj, another)) return true;
|
||||
if ((obj == null) || (another == null)) return false;
|
||||
if (obj.GetType() != another.GetType()) return false;
|
||||
|
||||
//properties: int, double, DateTime, etc, not class
|
||||
if (!obj.GetType().IsClass) return obj.Equals(another);
|
||||
|
||||
var result = true;
|
||||
foreach (var property in obj.GetType().GetProperties())
|
||||
{
|
||||
var objValue = property.GetValue(obj);
|
||||
var anotherValue = property.GetValue(another);
|
||||
//Recursion
|
||||
if (!objValue.DeepCompare(anotherValue)) result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue