public void When_getting_or_adding_value() { var oldValue = new Person { Name = "Joe", Age = 1 }; var someKeyedCollection = new KeyedCollectionEx <string, Person>(p => p.Name) { oldValue }; var newValue = new Person { Name = "Jim", Age = 1 }; oldValue.ShouldNotBe(newValue); someKeyedCollection.GetOrAdd("Joe", () => newValue).ShouldBe(oldValue); someKeyedCollection.GetOrAdd("Jim", () => newValue).ShouldBe(newValue); someKeyedCollection.Remove(newValue); someKeyedCollection.GetOrAdd("Joe", newValue).ShouldBe(oldValue); someKeyedCollection.GetOrAdd("Jim", newValue).ShouldBe(newValue); }
public Script CreateNewScript(string _name, string _source, string _tagStr, bool _enable = true, bool overwrite = true) { if (_name.Equals(string.Empty)) { return(null); } if (Scripts.Contains(_name)) { if (overwrite) { Scripts.Remove(_name); } else { return(null); } } Script t = new Script(_name, _source, _tagStr, _enable); t.Relink(); Add(t); return(t); }