// Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. #if !NET_4_6 using System.Collections.Generic; namespace System.Dynamic.Utils { // Miscellaneous helpers that don't belong anywhere else internal static class Helpers { internal static T CommonNode(T first, T second, Func parent) where T : class { // NOTICE this method has no null check var cmp = EqualityComparer.Default; if (cmp.Equals(first, second)) { return first; } var set = new HashSet(cmp); for (var t = first; t != null; t = parent(t)) { set.Add(t); } for (var t = second; t != null; t = parent(t)) { if (set.Contains(t)) { return t; } } return null; } internal static void IncrementCount(T key, Dictionary dict) { int count; dict.TryGetValue(key, out count); dict[key] = count + 1; } } } #endif