Monday, May 21, 2007

Get a list of the connections configured in an application

<Connections>
<add Type="WiredConnection" Price="1" />
<add Type="WirelessConnection" Price="2" />
</Connections>
You can obtain a list of the configured connections from the Connections property of the ConnectionMonitor.
ConnectionCollection connList = sampleMonitor.Connections;
The ConnectionCollection class inherits from the generic collection class KeyedCollection and implements the IEnumerable interface.

StringBuilder builder = new StringBuilder();
foreach (Connection conn in connList)
{
builder.Append(String.Format("Type: {0}, Price: {1}, "
+ "IsConnected: {2}",
conn.ConnectionTypeName,
conn.Price.ToString(),
conn.IsConnected.ToString()));
builder.Append("\n");
}

No comments: