public void AddChild(char child) { if (ChildrenSet.Add(child)) { Children.Add(child); } }
internal override void Remove(SettingItem setting) { if (setting == null) { throw new ArgumentNullException(nameof(setting)); } if (ChildrenSet.TryGetValue(setting, out var currentSetting)) { Debug.Assert(!currentSetting.IsAbstract()); if (currentSetting.Origin != null && currentSetting.Origin.IsMachineWide) { throw new InvalidOperationException(Resources.CannotUpdateMachineWide); } if (ChildrenSet.Remove(currentSetting)) { // Remove it from the appropriate config if (currentSetting.Parent != null && currentSetting.Parent != this) { currentSetting.Parent.Remove(currentSetting); } } if (currentSetting.MergedWith != null) { // Add that back to the set since, we should leave the machine wide setting intact. if (!TryRemoveAllMergedWith(currentSetting, out var undeletedItem)) { ChildrenSet.Add(undeletedItem, undeletedItem); } } } }
/// <remarks> /// There should not be a NuGetConfiguration without an Origin. /// This constructor should only be used for tests. /// </remarks> internal NuGetConfiguration(params SettingSection[] sections) : base() { foreach (var section in sections) { section.Parent = this; ChildrenSet.Add(section, section); } }
public void AddChildOrdered(char child) { if (ChildrenSet.Add(child)) { Children.Add(child); } if (Children.Count > 1) { Children.Sort((x, y) => x.CompareTo(y)); } }
internal override bool Add(SettingItem setting) { if (setting == null) { throw new ArgumentNullException(nameof(setting)); } if (!ChildrenSet.ContainsKey(setting) && !setting.IsEmpty()) { ChildrenSet.Add(setting, setting); return(true); } return(false); }
internal NuGetConfiguration(SettingsFile origin) : base() { var defaultSource = new SourceItem(NuGetConstants.FeedName, NuGetConstants.V3FeedUrl, protocolVersion: PackageSourceProvider.MaxSupportedProtocolVersion.ToString()); defaultSource.SetNode(defaultSource.AsXNode()); var defaultSection = new ParsedSettingSection(ConfigurationConstants.PackageSources, defaultSource) { Parent = this }; defaultSection.SetNode(defaultSection.AsXNode()); ChildrenSet.Add(defaultSection, defaultSection); SetNode(AsXNode()); SetOrigin(origin); }
internal VirtualSettingSection Merge(SettingSection other) { if (!Equals(other)) { throw new ArgumentException(Resources.Error_MergeTwoDifferentSections); } foreach (var item in other.Items.Where(item => item != null)) { if (item is ClearItem) { if (CanBeCleared) { ChildrenSet.Clear(); } ChildrenSet.Add(item, item); continue; } if (ChildrenSet.ContainsKey(item)) { if (item is UnknownItem unknown) { unknown.Merge(ChildrenSet[item] as UnknownItem); } item.MergedWith = ChildrenSet[item]; ChildrenSet[item] = item; } else { ChildrenSet.Add(item, item); } } return(this); }
internal bool Update(SettingItem item) { if (item == null || (Origin != null && Origin.IsMachineWide)) { return(false); } if (ChildrenSet.ContainsKey(item)) { var currentChild = ChildrenSet[item]; if (currentChild.Origin != null && currentChild.Origin.IsMachineWide) { return(false); } currentChild.Update(item); return(true); } return(false); }
public void ClearChildren() { Children.Clear(); ChildrenSet.Clear(); }
public void RemoveChild(char child) { Children.Remove(child); ChildrenSet.Remove(child); }
public override int GetHashCode() => ChildrenSet.GetHashCode();