Skip to content

Commit

Permalink
Fixed bug 'The node is not parented by this object' when IXProject.Re…
Browse files Browse the repository at this point in the history
…moveImport is used for `Import` elements inside `ImportGroup`.

Related issue: 3F/DllExport#77

Also updated signature: `bool RemoveImport(ImportElement element, bool holdEmptyGroup = true)`
  • Loading branch information
3F committed Jul 13, 2018
1 parent e23e44c commit 3a97c3a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion MvsSln/Core/IXProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ public interface IXProject
/// To remove 'Import' element.
/// </summary>
/// <param name="element">Specified 'Import' element to remove.</param>
/// <param name="holdEmptyGroup">Holds empty group if it was inside.</param>
/// <returns>true value if it has been removed.</returns>
bool RemoveImport(ImportElement element);
bool RemoveImport(ImportElement element, bool holdEmptyGroup = true);

/// <summary>
/// Retrieve the first found 'Import' element if it exists.
Expand Down
26 changes: 24 additions & 2 deletions MvsSln/Core/XProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,36 @@ public bool RemoveImport(string project)
/// To remove 'Import' element.
/// </summary>
/// <param name="element">Specified 'Import' element to remove.</param>
/// <param name="holdEmptyGroup">Holds empty group if it was inside.</param>
/// <returns>true value if it has been removed.</returns>
public bool RemoveImport(ImportElement element)
public bool RemoveImport(ImportElement element, bool holdEmptyGroup = true)
{
if(element.parentElement == null) {
return false;
}

Project.Xml.RemoveChild(element.parentElement);
// https://github.com/3F/DllExport/issues/77
// 'The node is not parented by this object' if an `Import` element is already placed inside `ImportGroup`.
//Project.Xml.RemoveChild(element.parentElement);

var imp = element.parentElement;
if(imp.Parent is ProjectImportGroupElement container)
{
if(container.Imports.Count > 1) {
container.RemoveChild(imp);
return true;
}

if(holdEmptyGroup) {
container.RemoveChild(imp); // leave as an ~ <ImportGroup />
}
else {
Project.Xml.RemoveChild(container);
}
return true;
}

Project.Xml.RemoveChild(imp);
return true;
}

Expand Down

0 comments on commit 3a97c3a

Please sign in to comment.