-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from ricaun-io/develop
Version 0.3.1
- Loading branch information
Showing
10 changed files
with
147 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
|
||
namespace ricaun.Revit.UI | ||
{ | ||
/// <summary> | ||
/// ObservableCollectionExtension | ||
/// </summary> | ||
internal static class ObservableCollectionExtension | ||
{ | ||
/// <summary> | ||
/// Sort <paramref name="collection"/> | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="collection"></param> | ||
/// <param name="comparison"></param> | ||
internal static void Sort<T>(this ObservableCollection<T> collection, Comparison<T> comparison) | ||
{ | ||
var sortableList = new List<T>(collection); | ||
sortableList.Sort(comparison); | ||
|
||
collection.Move(sortableList); | ||
} | ||
|
||
/// <summary> | ||
/// OrderBy <paramref name="collection"/> | ||
/// </summary> | ||
/// <typeparam name="TSource"></typeparam> | ||
/// <typeparam name="TKey"></typeparam> | ||
/// <param name="collection"></param> | ||
/// <param name="keySelector"></param> | ||
internal static void OrderBy<TSource, TKey>(this ObservableCollection<TSource> collection, Func<TSource, TKey> keySelector) | ||
{ | ||
var sortableList = new List<TSource>(collection); | ||
sortableList = sortableList.OrderBy(keySelector) | ||
.ToList(); | ||
|
||
collection.Move(sortableList); | ||
} | ||
|
||
/// <summary> | ||
/// OrderByDescending <paramref name="collection"/> | ||
/// </summary> | ||
/// <typeparam name="TSource"></typeparam> | ||
/// <typeparam name="TKey"></typeparam> | ||
/// <param name="collection"></param> | ||
/// <param name="keySelector"></param> | ||
internal static void OrderByDescending<TSource, TKey>(this ObservableCollection<TSource> collection, Func<TSource, TKey> keySelector) | ||
{ | ||
var sortableList = new List<TSource>(collection); | ||
sortableList = sortableList.OrderByDescending(keySelector) | ||
.ToList(); | ||
|
||
collection.Move(sortableList); | ||
} | ||
|
||
/// <summary> | ||
/// Move <paramref name="collection"/> based on <paramref name="sortableList"/> | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="collection"></param> | ||
/// <param name="sortableList"></param> | ||
private static void Move<T>(this ObservableCollection<T> collection, List<T> sortableList) | ||
{ | ||
for (int i = 0; i < sortableList.Count; i++) | ||
{ | ||
collection.Move(collection.IndexOf(sortableList[i]), i); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters