Exemple #1
0
        public virtual void UpdateState(T t, ExtractedParameters state)
        {
            var dispatchee = t as Dispatchee <T>;

            dispatchee.ThrowIfNull(nameof(t));

            if (state.HasValue(nameof(Coordinates)))
            {
                dispatchee.Coordinates = state.ToValue <Coordinate>(nameof(Coordinates));
            }
        }
        public override void UpdateState(Maze clone, ExtractedParameters state)
        {
            if (state.HasValue(nameof(Tiles.Tiles)))
            {
                var tiles        = state.ToString(nameof(Tiles.Tiles));
                var tilesChanged = tiles.ToTiles();

                foreach (var tileChange in tilesChanged)
                {
                    clone._tiles[tileChange.Coordinates] = tileChange.Name;
                }
            }

            base.UpdateState(clone, state);
        }
        public static T ToValue <T>(this ExtractedParameters parameters, string name) where T : struct
        {
            var value = parameters.ToString(name);

            switch (typeof(T).Name)
            {
            case "Int32": return((T)Convert.ChangeType(int.Parse(value), typeof(T)));

            case "Double": return((T)Convert.ChangeType(double.Parse(value), typeof(T)));

            case "Compass8Points": return((T)Convert.ChangeType(value.ToEnum <T>(), typeof(T)));

            case "Coordinate": return((T)Convert.ChangeType(value.ToCoordinates(), typeof(T)));
            }

            throw new ArgumentException($"Unable to convert [{name}:{value}] to type [{typeof(T).Name}]");
        }
        public void MoveImpl(ExtractedParameters parameters)
        {
            var dispatchee     = parameters.GetDispatchee("Dispatchee", Registry);
            var direction      = parameters.ToValue <Compass8Points>("Direction");
            var newCoordinates = dispatchee.Coordinates.Move(direction);

            if (!_tiles.IsInside(newCoordinates))
            {
                return;
            }
            if (!_tiles[newCoordinates].IsNullOrEmpty())
            {
                return;
            }

            PlaceInMaze(dispatchee, newCoordinates);
        }
        public static bool HasValue(this ExtractedParameters parameters, string name)
        {
            var value = parameters.SingleOrDefault(param => param.Name == name);

            return(!value.Name.IsNullOrEmpty() && !value.Value.IsNullOrEmpty());
        }
        public static IDispatchee GetDispatchee(this ExtractedParameters parameters, string name, DispatchRegistry registry)
        {
            var value = parameters.ToString(name);

            return(registry.GetDispatchee(value));
        }
 public static string ToString(this ExtractedParameters parameters, string name)
 {
     return(parameters.Single(param => param.Name == name).Value);
 }
Exemple #8
0
 public ReadOnlyList(System.Collections.Generic.IReadOnlyList <TSource> innerList, Converter <TSource, TDestination> selector) : base(innerList, selector) /* Left empty. */
 {
 }