public virtual int CloseChildren()
{
int returnValue = VSConstants.S_OK; // be optimistic.
IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;
Debug.Assert(solution != null, "Could not retrieve the solution from the services provided by this project");
if(solution == null)
{
return VSConstants.E_FAIL;
}
IntPtr iUnKnownForSolution = IntPtr.Zero;
try
{
iUnKnownForSolution = Marshal.GetIUnknownForObject(solution);
// notify SolutionEvents listeners that we are about to close children
IVsFireSolutionEvents fireSolutionEvents = Marshal.GetTypedObjectForIUnknown(iUnKnownForSolution, typeof(IVsFireSolutionEvents)) as IVsFireSolutionEvents;
ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnBeforeClosingChildren(this));
// If the removal crashes we never fire the close children event. IS that a problem?
this.RemoveNestedProjectNodes();
ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnAfterClosingChildren(this));
}
finally
{
if(iUnKnownForSolution != IntPtr.Zero)
{
Marshal.Release(iUnKnownForSolution);
}
}
return returnValue;
}