Ejemplo n.º 1
0
        public static TrackableSpaceShipDataTrackerSurrogate Convert(TrackablePocoTracker <ISpaceShipData> tracker)
        {
            if (tracker == null)
            {
                return(null);
            }

            var surrogate = new TrackableSpaceShipDataTrackerSurrogate();

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

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

            return(surrogate);
        }
Ejemplo n.º 2
0
        public static TrackablePocoTracker <ISpaceShipData> Convert(TrackableSpaceShipDataTrackerSurrogate surrogate)
        {
            if (surrogate == null)
            {
                return(null);
            }

            var tracker = new TrackablePocoTracker <ISpaceShipData>();

            if (surrogate.Hp != null)
            {
                tracker.ChangeMap.Add(TrackableSpaceShipData.PropertyTable.Hp, new TrackablePocoTracker <ISpaceShipData> .Change {
                    NewValue = surrogate.Hp.Value
                });
            }
            if (surrogate.Score != null)
            {
                tracker.ChangeMap.Add(TrackableSpaceShipData.PropertyTable.Score, new TrackablePocoTracker <ISpaceShipData> .Change {
                    NewValue = surrogate.Score.Value
                });
            }
            return(tracker);
        }