Skip to content

Instantly share code, notes, and snippets.

View DictionaryExtensions.cs
public static class DictionaryExtensions
{
public static TValue Get<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue))
=> dict.TryGetValue(key, out var actualValue) ? actualValue : defaultValue;
public static TValue Get<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue))
=> dict.TryGetValue(key, out var actualValue) ? actualValue : defaultValue;
public static TValue Get<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue))
@GrahamTheCoder
GrahamTheCoder / GetNewAndEditedLineRangesFromMaster.ps1
Created Jul 1, 2016
Gets a list of line ranges (index and length if more than 1) for files changed since diverging from origin master
View GetNewAndEditedLineRangesFromMaster.ps1
function Get-LinesChanged() {
$diffFromCommonBase = git diff origin/master...HEAD --unified=0 --dst-prefix=""
$linesByFile = @{}
$currentLines = New-Object System.Collections.ArrayList
foreach ($diffLine in $diffFromCommonBase ) {
if ($diffLine.StartsWith("+++")) {
#e.g. "+++ Path/to/file.cs" -> "Path/to/file.cs"
$currentFile = $diffLine.Substring(4)
$currentLines = $linesByFile[$currentFile] = New-Object System.Collections.ArrayList