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
public static async Task WaitForValue<T>(this INotifyPropertyChanged toObserve, | |
Expression<Func<T>> propertyExpression, | |
T valueToAwait, | |
IEqualityComparer<T> comparer = null) | |
{ | |
comparer = comparer ?? EqualityComparer<T>.Default; | |
var getValue = propertyExpression.Compile(); | |
if (comparer.Equals(getValue(), valueToAwait)) | |
return; |
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
public static class EnumerableExtensions | |
{ | |
public static string StringJoin<T>(this IEnumerable<T> source, string delimiter) | |
{ | |
return string.Join(delimiter, source); | |
} | |
} |
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
public static class ObservableCollectionExtensions | |
{ | |
public static IDisposable SuppressCollectionEvents(this INotifyCollectionChanged collection, | |
bool fireEventWhenComplete = true) | |
{ | |
return new CollectionEventSuppressor(collection, fireEventWhenComplete); | |
} | |
private class CollectionEventSuppressor : IDisposable | |
{ |
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
IEnumerable<string> GetAlternateSpellings(string baseName) | |
{ | |
if (string.IsNullOrWhiteSpace(baseName)) | |
yield break; | |
yield return baseName; | |
if (baseName.Contains("_")) | |
{ | |
yield return Regex.Replace(baseName, @"(_)([a-z])", m => m.Groups.Cast<Group>().Last().Value.ToUpper()); | |
} |
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
/// <summary> | |
/// Signals the compiler that this task should be allowed to run independently. | |
/// </summary> | |
/// <param name="task"></param> | |
public static void Release(this Task task) | |
{ | |
} |
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
public class Selectable<T> : ViewModelBase | |
{ | |
private bool _isSelected; | |
public Selectable(T item) | |
{ | |
Item = item; | |
IsSelected = false; | |
} |
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
/// <summary> | |
/// Recursively searches a tree structure for a specific node. | |
/// </summary> | |
/// <typeparam name="TChild">The node's type.</typeparam> | |
/// <typeparam name="TIdentifier">The node identifier's type</typeparam> | |
/// <param name="root">The root node to search under.</param> | |
/// <param name="identifier">The identifier of the node to find.</param> | |
/// <param name="childSelector">A function that returns a node's children in the tree.</param> | |
/// <param name="identifierSelector">A function that returns a node's identifier</param> | |
/// <returns>Either a <cref>TChildType</cref> instance whose identifier matches the one specified, or null if not found.</returns> |
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
public static IEnumerable<U> SelectIfNotNull<T, U>(this IEnumerable<T> source, Func<T, U> mapper) | |
{ | |
foreach (var sourceItem in source) | |
{ | |
var resultItem = mapper(sourceItem); | |
if (resultItem != null) | |
{ | |
yield return resultItem; | |
} | |
} |
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
public static class PointExtensions | |
{ | |
public static double DistanceFrom(this Point point1, Point point2) | |
{ | |
// Pythagorean distance calculation. | |
return Math.Abs( | |
Math.Sqrt( | |
Math.Pow(point1.X - point2.X, 2) + Math.Pow(point1.Y - point2.Y, 2) | |
) | |
); |
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
public static async Task<TBase> Upcast<TDerived, TBase> (this Task<TDerived> task) where TDerived : TBase | |
{ | |
return (TBase) await task; | |
} |
NewerOlder