using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public static void Main() {
var variances = p1.Compare(p2);
var props = variances.Aggregate(string.Empty, (a, next) => $"{ a }\r\n\t{ next.PropertyName }: { next.valA } | { next.valB }");
Console.WriteLine($"There were { variances.Count } variances on these properties: { props }");
public string PropertyName { get; set; }
public object valA { get; set; }
public object valB { get; set; }
public static class Comparision {
public static List<Variance> Compare<T>(this T val1, T val2) {
var variances = new List<Variance>();
var properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var property in properties) {
var name = property.GetCustomAttribute<DisplayAttribute>()?.Name;
PropertyName = name ?? property.Name,
valA = property.GetValue(val1),
valB = property.GetValue(val2)
if (v.valA == null && v.valB == null) {
(v.valA == null && v.valB != null)
(v.valA != null && v.valB == null)
if (!v.valA.Equals(v.valB)) {
[Display(Name = "Person Id")]
public Guid Id { get; set; }
[Display(Name = "Person Firstname")]
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public string HairColor { get; set; }