I have a dozen classes that inherit from the same baseclass. For each class, I want to change the state when a property updates, so I have a function called UpdateProperty(oldValue, newValue). I'm looking for a way to make these generic, so when I add a new class, I don't have to add a new function. This is what I have:
public TicketType UpdateProperty(TicketType oldValue, TicketType newValue)
{
if (oldValue != newValue && ObjectState != ObjectState.New && ObjectState != ObjectState.Deleted)
{
ObjectState = ObjectState.Changed;
}
return newValue;
}
public Layout UpdateProperty(Layout oldValue, Layout newValue)
{
if (oldValue != newValue && ObjectState != ObjectState.New && ObjectState != ObjectState.Deleted)
{
ObjectState = ObjectState.Changed;
}
return newValue;
}
public Division UpdateProperty(Division oldValue, Division newValue)
{
if (oldValue != newValue && ObjectState != ObjectState.New && ObjectState != ObjectState.Deleted)
{
ObjectState = ObjectState.Changed;
}
return newValue;
}
public MasterDataList UpdateProperty(MasterDataList oldValue, MasterDataList newValue)
{
if (oldValue != newValue && ObjectState != ObjectState.New && ObjectState != ObjectState.Deleted)
{
ObjectState = ObjectState.Changed;
}
return newValue;
}
public MasterDataListItem UpdateProperty(MasterDataListItem oldValue, MasterDataListItem newValue)
{
if (oldValue != newValue && ObjectState != ObjectState.New && ObjectState != ObjectState.Deleted)
{
ObjectState = ObjectState.Changed;
}
return newValue;
}
public Ticket UpdateProperty(Ticket oldValue, Ticket newValue)
{
if (oldValue != newValue && ObjectState != ObjectState.New && ObjectState != ObjectState.Deleted)
{
ObjectState = ObjectState.Changed;
}
return newValue;
}
As you can see, they all do the same. Could someone point me in the right direction?
Also see https://dotnetfiddle.net/xXgRuv