Dienstag, 4. März 2008

Visual Studio 2008 SDK Goodies #3

Here's another goodie from the Visual Studio 2008 SDK. In
ProjectNode.CopyPaste.cs in the namespace Microsoft.VisualStudio.Package you'll find the following code snippet:

StringBuilder selectionContent = null;

// If there is a selection package the data
if (selectedNodes.Count > 1)
{
foreach (HierarchyNode node in selectedNodes)
{
selectionContent = node.PrepareSelectedNodesForClipBoard();
if (selectionContent != null)
{
sb.Append(selectionContent);
}
}
}
else if (selectedNodes.Count == 1)
{
HierarchyNode selectedNode = selectedNodes[0];
selectionContent = selectedNode.PrepareSelectedNodesForClipBoard();
if (selectionContent != null)
{
sb.Append(selectionContent);
}
}


Why do we need this if - else if construct? Does the foreach for a list with zero or one element not work?

Keine Kommentare:

Reach me via Live Messenger