/// <summary> /// Adds, deletes or updates with new variable change request data inside the current session. /// </summary> public void Update(EnvironmentSessionItem item) { if (item == null) { throw new ArgumentNullException("item"); } if (item.Target != EnvironmentVariableTarget.Process) { Update(new EnvironmentSessionItem(EnvironmentVariableTarget.Process, item.Name, item.Value, item.PrimaryValue)); } EnvironmentSessionItem existingItem = GetVariable(item.Target, item.Name); bool notify = false; if (existingItem != null) { // if new value set to environment variable // is the same as the original value, // then we can remove it: if (existingItem.PrimaryValue == item.Value) { _items.Remove(existingItem); notify = true; } else { if (existingItem.Value != item.Value) { existingItem.Value = item.Value; notify = true; } } } else { _items.Add(item); notify = true; } if (notify && Changed != null) { Changed(this, new EnvironmentSessionEventArgs(_items.Count)); } }