Skip to main content

Posts

Showing posts from February, 2019

Extension Method To Compare 2 Objects

Extension Method To Compare 2 Objects https://stackoverflow.com/questions/10454519/best-way-to-compare-two-complex-objects  or use this public static class ObjectComparer {     public static bool CompareObj(this object source, object destination)     {         if (!source.GetType().Equals(destination.GetType()))             return false;         var properties = source.GetType().GetProperties();         foreach (var item in properties)             if (!item.GetValue(source, null).Equals(item.GetValue(destination)))                 return false;         return true;     } } Usage Create 2 classes. class Program     {         static void Main(string[] args)         {       ...