Amoeba.Windows.ChatCategorizeTreeViewModel.Sort C# (CSharp) Method

Sort() public method

public Sort ( ) : void
return void
        public void Sort()
        {
            var list = _children.Cast<TreeViewModelBase>().ToList();

            list.Sort((x, y) =>
            {
                if (x is ChatCategorizeTreeViewModel)
                {
                    if (y is ChatCategorizeTreeViewModel)
                    {
                        var vx = ((ChatCategorizeTreeViewModel)x).Value;
                        var vy = ((ChatCategorizeTreeViewModel)y).Value;

                        int c = vx.Name.CompareTo(vy.Name);
                        if (c != 0) return c;
                        c = vx.ChatTreeItems.Count.CompareTo(vy.ChatTreeItems.Count);
                        if (c != 0) return c;
                        c = vx.GetHashCode().CompareTo(vy.GetHashCode());
                        if (c != 0) return c;
                    }
                    else if (y is ChatTreeViewModel)
                    {
                        return 1;
                    }
                }
                else if (x is ChatTreeViewModel)
                {
                    if (y is ChatTreeViewModel)
                    {
                        var vx = ((ChatTreeViewModel)x).Value;
                        var vy = ((ChatTreeViewModel)y).Value;

                        int c = vx.Tag.Name.CompareTo(vy.Tag.Name);
                        if (c != 0) return c;
                        c = CollectionUtils.Compare(vx.Tag.Id, vy.Tag.Id);
                        if (c != 0) return c;
                        c = vx.GetHashCode().CompareTo(vy.GetHashCode());
                        if (c != 0) return c;
                    }
                    else if (y is ChatCategorizeTreeViewModel)
                    {
                        return -1;
                    }
                }

                return 0;
            });

            for (int i = 0; i < list.Count; i++)
            {
                var o = _children.IndexOf(list[i]);

                if (i != o) _children.Move(o, i);
            }
        }