Exemplo n.º 1
0
        public static void MoveAfter <T>(this IGraphModel self, IReadOnlyList <T> models, T insertAfter) where T : class, IGraphElementModel
        {
            List <T> list = (List <T>)self.GetListOf <T>();

            if (insertAfter != null)
            {
                var insertAfterIndex = list.IndexOf(insertAfter);
                while (insertAfterIndex >= 0 && models.Contains(list[insertAfterIndex]))
                {
                    insertAfterIndex--;
                }

                if (insertAfterIndex >= 0)
                {
                    insertAfter = list[insertAfterIndex];
                }
                else
                {
                    insertAfter = null;
                }
            }

            foreach (var model in models)
            {
                list.Remove(model);
            }

            var insertionIndex = 0;

            if (insertAfter != null)
            {
                insertionIndex = list.IndexOf(insertAfter) + 1;
            }

            foreach (var model in models)
            {
                list.Insert(insertionIndex++, model);
            }
        }
Exemplo n.º 2
0
        public static void MoveBefore <T>(this IGraphModel self, IReadOnlyList <T> models, T insertBefore) where T : class, IGraphElementModel
        {
            List <T> list = (List <T>)self.GetListOf <T>();

            if (insertBefore != null)
            {
                var insertBeforeIndex = list.IndexOf(insertBefore);
                while (insertBeforeIndex < list.Count && models.Contains(list[insertBeforeIndex]))
                {
                    insertBeforeIndex++;
                }

                if (insertBeforeIndex < list.Count)
                {
                    insertBefore = list[insertBeforeIndex];
                }
                else
                {
                    insertBefore = null;
                }
            }

            foreach (var model in models)
            {
                list.Remove(model);
            }

            var insertionIndex = list.Count;

            if (insertBefore != null)
            {
                insertionIndex = list.IndexOf(insertBefore);
            }

            foreach (var model in models)
            {
                list.Insert(insertionIndex++, model);
            }
        }