예제 #1
0
        public static CIList ciInsert(CIList list, CIPredicate predicate, int indexDelta, int maxMatchCount, params object[] cinsToInsert)
        {
            bool anyInserts = false;             // just for assert
            int  index, index0 = 0;

            var listToInsert   = toCIList(cinsToInsert);
            int indexIncrement = listToInsert.Count + Math.Max(1, indexDelta);

            while ((index = list.FindIndex(index0, predicate)) != -1 && (anyInserts = true))
            {
                ciInsert(list, index + indexDelta, listToInsert);
                Debug.assert(indexDelta <= 1 || list.FindIndex(index + 1, indexDelta - 1, predicate) == -1); // just in case if indexDelta > 1

                index0 = index + indexIncrement;                                                             // next after finded or next after inserted

                if (--maxMatchCount == 0)
                {
                    break;
                }

                listToInsert = copyCIList(listToInsert);                 // better make copy if need to insert this more than once (there might be a problems with labels otherwise)
            }

            Debug.assert(anyInserts, $"ciInsert: no insertions were made");
            Debug.assert(maxMatchCount <= 0, $"ciInsert: matchCount {maxMatchCount}");

            return(list);
        }
예제 #2
0
 public static CIList ciReplace(CIList list, CIPredicate predicate, params object[] cinsForReplace) =>
 ciReplace(list, list.FindIndex(predicate), cinsForReplace);
예제 #3
0
        public static CIList ciRemove(CIList list, CIPredicate predicate, int indexDelta, int countToRemove)
        {
            int index = list.FindIndex(predicate);

            return(ciRemove(list, (index == -1? -1: index + indexDelta), countToRemove));
        }