check properties of two objects for changes

Posted by k-hoffmann on Stack Overflow See other posts from Stack Overflow or by k-hoffmann
Published on 2010-06-16T08:06:06Z Indexed on 2010/06/16 8:32 UTC
Read the original article Hit count: 219

Filed under:
|
|

Hi,

i have to develop a mechanism to check two object properties for changes.
All properties which are needed to check are marked with an attribute.

Atm i
- read all properties from acutal object via linq
- read the corresponding property from old object
- fill an own object with the two properties (old and new value)

In Code the call to the workerclass looks like this

    public void CreateHistoryMap(BaseEntity actual, BaseEntity old)
    {
        CreateHistoryMap(actualEntity, oldEntity)
                       .ForEach(mapEntry => CreateHistoryEntry(mapEntry),
                                mapEntry => IfChangesDetected(mapEntry));
    }

CreateHistoryMap builds up the HistoryMapEntry which contains the two properties.
CreateHistoryEntry build up the object which is saved to database, the IfChangesDetected check the object for changes.

I have to handle own special application types to generate history values to database (like concatinating list values and so on).

My problem is now, that i have to read the values of the properties twice
- for change detection
- and for the concreate CreateHistoryEntry

How can i eliminate this problem or how can i implement the change tracking scenario with the nice c# 3.5 features?

Thanks a lot.

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection