public void SetExceptionBehavior(ExceptionBehaviorMap newMap) { var changed = _exceptionBehaviorMap.CopyFrom(newMap); if (!_wasPrepared || changed.Count == 0) { return; } SetupBehaviors(changed); }
/// <summary> /// Copy the state of the given object to me. /// </summary> public void CopyFrom(ExceptionBehaviorMap source) { lock (mapLock) { DefaultStopOnThrow = source.DefaultStopOnThrow; DefaultStopUncaught = source.DefaultStopUncaught; map.Clear(); foreach (var entry in source.map) { map[entry.Key] = entry.Value; } } }
/// <summary> /// Copy the state of the given object to me. /// /// Returns all behaviors that have changed, with their new values. /// If the default behavior was changed, the first returned behavior /// will be null. /// </summary> public IList <ExceptionBehavior> CopyFrom(ExceptionBehaviorMap source) { source = source.Clone(); lock (mapLock) { List <string> changed = new List <string>(); // find changed values foreach (var entry in source.map) { if (!Equals(this[entry.Key], entry.Value)) { changed.Add(entry.Key); } } // add all values that have been removed. changed.AddRange(map.Keys.ToList() .Where(key => !source.map.ContainsKey(key))); map.Clear(); foreach (var entry in source.map) { map[entry.Key] = entry.Value; } List <ExceptionBehavior> ret = new List <ExceptionBehavior>(); if (DefaultStopUncaught != source.DefaultStopUncaught || DefaultStopOnThrow != source.DefaultStopOnThrow) { ret.Insert(0, null); } ret.AddRange(changed.Select(x => this[x])); DefaultStopOnThrow = source.DefaultStopOnThrow; DefaultStopUncaught = source.DefaultStopUncaught; return(ret); } }
public void SetExceptionBehavior(ExceptionBehaviorMap newMap) { var changed = _exceptionBehaviorMap.CopyFrom(newMap); if (!_wasPrepared || changed.Count == 0) return; SetupBehaviors(changed); }
private ExceptionBehaviorMap(ExceptionBehaviorMap copy) { DefaultStopOnThrow = copy.DefaultStopOnThrow; DefaultStopUncaught = copy.DefaultStopUncaught; map = new Dictionary<string, ExceptionBehavior>(copy.map); }
/// <summary> /// Copy the state of the given object to me. /// /// Returns all behaviors that have changed, with their new values. /// If the default behavior was changed, the first returned behavior /// will be null. /// </summary> public IList<ExceptionBehavior> CopyFrom(ExceptionBehaviorMap source) { source = source.Clone(); lock (mapLock) { List<string> changed = new List<string>(); // find changed values foreach (var entry in source.map) { if (!Equals(this[entry.Key], entry.Value)) changed.Add(entry.Key); } // add all values that have been removed. changed.AddRange(map.Keys.ToList() .Where(key => !source.map.ContainsKey(key))); map.Clear(); foreach (var entry in source.map) { map[entry.Key] = entry.Value; } List<ExceptionBehavior> ret = new List<ExceptionBehavior>(); if(DefaultStopUncaught != source.DefaultStopUncaught || DefaultStopOnThrow != source.DefaultStopOnThrow) ret.Insert(0, null); ret.AddRange(changed.Select(x => this[x])); DefaultStopOnThrow = source.DefaultStopOnThrow; DefaultStopUncaught = source.DefaultStopUncaught; return ret; } }
private ExceptionBehaviorMap(ExceptionBehaviorMap copy) { DefaultStopOnThrow = copy.DefaultStopOnThrow; DefaultStopUncaught = copy.DefaultStopUncaught; map = new Dictionary <string, ExceptionBehavior>(copy.map); }