protected bool GetOwnBuildActions(int inputWeight, out WeightedBuildActionBag?actionBag) { actionBag = null; if (_buildActions is null) { return(false); } var matchingWeight = inputWeight + Weight; actionBag = new WeightedBuildActionBag(); foreach (var pair in _buildActions) { actionBag.Add(pair.Key, pair.Value.Select(_ => _.WithWeight(matchingWeight)).ToList()); } return(true); }
public static WeightedBuildActionBag?Merge(this WeightedBuildActionBag?left, WeightedBuildActionBag?right) { if (left is null) { return(right); } if (right is null) { return(left); } var result = new WeightedBuildActionBag(); foreach (var pair in left) { List <Weighted <IBuildAction> > resultValue; if (!right.TryGetValue(pair.Key, out var rightValue)) // if key is presented only in 'left' dictionary - get value from it { resultValue = pair.Value; } else // if key is presented in both dictionaries create a new list and merge items from both { resultValue = new List <Weighted <IBuildAction> >(pair.Value); resultValue.AddRange(rightValue); } result.Add(pair.Key, resultValue); } foreach (var pair in right) { if (!left.ContainsKey(pair.Key)) { result.Add(pair.Key, pair.Value); // for all keys presented in 'right' and not presented in 'left' dictionary get value from 'right' } } return(result); }