예제 #1
0
        //...

        public bool Coerce(IList input)
        {
            if (input.Count > Value)
            {
                //Always >= 1
                var blocks = new string[Floor(input.Count.Double() / Value.Double()).Int32()];
                switch (Action)
                {
                case Actions.Clear:
                    for (var i = 0; i < (blocks.Length * Value); i++)
                    {
                        input.RemoveAt(0);
                    }

                    break;

                case Actions.ClearAndArchive:

                    if (input is ISerialize serializer)
                    {
                        if (Value > 0)
                        {
                            for (var i = 0; i < blocks.Length; i++)
                            {
                                var items = new object[Value];
                                for (var j = 0; j < items.Length; j++)
                                {
                                    items[j] = items[0];
                                    input.RemoveAt(0);
                                }

                                blocks[i] = StoragePath.Clone(serializer.FilePath, StoragePath.DefaultCloneFormat, j => System.IO.File.Exists(j));
                                serializer?.Serialize(blocks[i], items);
                            }
                        }
                    }
                    else
                    {
                        goto case Actions.Clear;
                    }
                    break;

                case Actions.RemoveFirst:
                    for (var i = 0; i < (blocks.Length * Value); i++)
                    {
                        input.RemoveAt(0);
                    }

                    break;

                case Actions.RemoveLast:
                    for (var i = 0; i < (blocks.Length * Value); i++)
                    {
                        input.RemoveAt(input.Count - 1);
                    }

                    break;
                }
                return(true);
            }
            return(false);
        }