Ejemplo n.º 1
0
        public static TrackablePocoTracker <IPerson> Convert(TrackablePersonTrackerSurrogate surrogate)
        {
            if (surrogate == null)
            {
                return(null);
            }

            var tracker = new TrackablePocoTracker <IPerson>();

            if (surrogate.Name != null)
            {
                tracker.ChangeMap.Add(TrackablePerson.PropertyTable.Name, new TrackablePocoTracker <IPerson> .Change {
                    NewValue = surrogate.Name.Value
                });
            }
            if (surrogate.Age != null)
            {
                tracker.ChangeMap.Add(TrackablePerson.PropertyTable.Age, new TrackablePocoTracker <IPerson> .Change {
                    NewValue = surrogate.Age.Value
                });
            }
            if (surrogate.LeftHand != null)
            {
                tracker.ChangeMap.Add(TrackablePerson.PropertyTable.LeftHand, new TrackablePocoTracker <IPerson> .Change {
                    NewValue = surrogate.LeftHand.Value
                });
            }
            if (surrogate.RightHand != null)
            {
                tracker.ChangeMap.Add(TrackablePerson.PropertyTable.RightHand, new TrackablePocoTracker <IPerson> .Change {
                    NewValue = surrogate.RightHand.Value
                });
            }
            return(tracker);
        }
Ejemplo n.º 2
0
        public static TrackablePersonTrackerSurrogate Convert(TrackablePocoTracker <IPerson> tracker)
        {
            if (tracker == null)
            {
                return(null);
            }

            var surrogate = new TrackablePersonTrackerSurrogate();

            foreach (var changeItem in tracker.ChangeMap)
            {
                switch (changeItem.Key.Name)
                {
                case "Name":
                    surrogate.Name = new EnvelopedObject <string> {
                        Value = (string)changeItem.Value.NewValue
                    };
                    break;

                case "Age":
                    surrogate.Age = new EnvelopedObject <int> {
                        Value = (int)changeItem.Value.NewValue
                    };
                    break;

                case "LeftHand":
                    surrogate.LeftHand = new EnvelopedObject <TrackableHand> {
                        Value = (TrackableHand)changeItem.Value.NewValue
                    };
                    break;

                case "RightHand":
                    surrogate.RightHand = new EnvelopedObject <TrackableHand> {
                        Value = (TrackableHand)changeItem.Value.NewValue
                    };
                    break;
                }
            }

            return(surrogate);
        }