I have the following class:
public class CompareField<T>
{
public CompareField()
{
Status = FieldStatus.NoChange;
}
public CompareField(T value)
{
Value = value;
Status = FieldStatus.NoChange;
}
public T Value { get; set; }
public FieldStatus Status { get; set; }
public bool Equals(T objectValue)
{
if (!Equals(Value, default(T)) || !Equals(objectValue, default(T))) return false;
return Value.Equals(objectValue);
}
}
public enum FieldStatus
{
NoChange = 0,
HasChanges = 1
}
So my model would contain a bunch of properties, that all use the CompareField type (like CompareField<'string> FirstName {get;set;}...
Now I want to compare two models to eachother and set the FieldStatus of each field, based on the fact that the fields are equal or different.
I've tried using the solution from this post, but it only touches on the comparison part...I can't actually set any properties using that method.
Also, what should I do if T is more complex than just a simple type? Let's say T is a List of classes, what should I use then?
I'm unsure how to implement this (and just using reflection would probably be too slow)...
Any tips would be helpful :)
EDIT So an example would be
ModelA
Firstname : Bob
Lastname : Test
ModelB
Firstname : Bobby
Lastname : Test
So I'd like "something" to compare ModelA to ModelB and get the following result
ModelA
Firstname : Bob - HasChanges
Lastname : Test - NoChanges
so by hand it would be something like
if (!modelA.FirstName.Value.Equals(modelB.FirstName.Value))
modelA.FirstName.Status = FieldStatus.HasChanges