ValeraT1982 / ObjectsComparer

C# Framework provides mechanism to compare complex objects, allows to override comparison rules for specific properties and types.
MIT License
354 stars 87 forks source link

Int? object property result a cast issue #22

Closed muradsun closed 3 years ago

muradsun commented 3 years ago

Try this

Class object1 { int? numericManagerId = null } Class object2 { int? numericManagerId = 120 }

var matched = _comparer.Compare(object1, object2, out var differences); var y = differences.ToList().Count();

Bellow Error will popup: System.InvalidCastException HResult=0x80004002 Message=Unable to cast object of type 'System.Int32' to type 'System.String'. Source=System.Private.CoreLib StackTrace: at System.Runtime.CompilerServices.CastHelpers.ChkCastAny(Void* toTypeHnd, Object obj) at ObjectsComparer.AbstractValueComparer1.Compare(Object obj1, Object obj2, ComparisonSettings settings) at ObjectsComparer.Comparer1.d__4.MoveNext() at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source) . . . .

ValeraT1982 commented 3 years ago

@muradsun can you please provide all code for your example? In the code you provided you declare 2 classes object1 and object2, then you use these class names as variable names. How _comparer variable was initialized?