public static int UniversalComparer(CustomListBoxItem item1, CustomListBoxItem item2) { if (item1.GetType() == item2.GetType()) { switch (item1) { case BranchListItem branchItem: return(BranchListItem.CompareByName(branchItem, (BranchListItem)item2)); case RemoteBranchListItem remoteBranchItem: return(RemoteBranchListItem.CompareByName(remoteBranchItem, (RemoteBranchListItem)item2)); case RemoteListItem remoteItem: return(RemoteListItem.CompareByName(remoteItem, (RemoteListItem)item2)); case TagListItem tagItem: return(TagListItem.CompareByName(tagItem, (TagListItem)item2)); default: return(0); } } else { switch (item1) { case BranchListItem _: return(-1); case RemoteBranchListItem _: return(item2 is BranchListItem ? 1 : -1); case RemoteListItem _: return(item2 is TagListItem ? 1 : -1); default: return(1); } } }
public static int UniversalComparer(CustomListBoxItem item1, CustomListBoxItem item2) { if (item1.GetType() == item2.GetType()) { var branchItem = item1 as BranchListItem; if (branchItem != null) { return(BranchListItem.CompareByName(branchItem, (BranchListItem)item2)); } var remoeBranchItem = item1 as RemoteBranchListItem; if (remoeBranchItem != null) { return(RemoteBranchListItem.CompareByName(branchItem, (RemoteBranchListItem)item2)); } var remoteItem = item1 as RemoteListItem; if (remoteItem != null) { return(RemoteListItem.CompareByName(remoteItem, (RemoteListItem)item2)); } var tagItem = item1 as TagListItem; if (tagItem != null) { return(TagListItem.CompareByName(tagItem, (TagListItem)item2)); } return(0); } else { var branchItem = item1 as BranchListItem; if (branchItem != null) { return(-1); } var remoteBranchItem = item1 as RemoteBranchListItem; if (remoteBranchItem != null) { var branchItem2 = item2 as BranchListItem; if (branchItem2 != null) { return(1); } else { return(-1); } } var remoteListItem = item1 as RemoteListItem; if (remoteListItem != null) { var tagItem2 = item2 as TagListItem; if (tagItem2 == null) { return(-1); } else { return(1); } } return(1); } }