diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-10-30 03:29:27 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-10-30 03:29:27 -0400 |
| commit | d31b0f7be4b14e4ada999c97e675b856ad68352b (patch) | |
| tree | a4619513efbb3be62a6204c996526df606cb62c5 /RSSDP/SsdpDeviceExtensions.cs | |
| parent | b19f75fcae017cb51f1e58eb2d54ca84620b6ee0 (diff) | |
| parent | 3094cd7ff3e51578808ce1b6f56b141930c18004 (diff) | |
Merge pull request #2258 from MediaBrowser/dev
Dev
Diffstat (limited to 'RSSDP/SsdpDeviceExtensions.cs')
| -rw-r--r-- | RSSDP/SsdpDeviceExtensions.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/RSSDP/SsdpDeviceExtensions.cs b/RSSDP/SsdpDeviceExtensions.cs new file mode 100644 index 0000000000..0ad710a6b0 --- /dev/null +++ b/RSSDP/SsdpDeviceExtensions.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Rssdp +{ + /// <summary> + /// Extensions for <see cref="SsdpDevice"/> and derived types. + /// </summary> + public static class SsdpDeviceExtensions + { + + /// <summary> + /// Returns the root device associated with a device instance derived from <see cref="SsdpDevice"/>. + /// </summary> + /// <param name="device">The device instance to find the <see cref="SsdpRootDevice"/> for.</param> + /// <remarks> + /// <para>The <paramref name="device"/> must be or inherit from <see cref="SsdpRootDevice"/> or <see cref="SsdpEmbeddedDevice"/>, otherwise an <see cref="System.InvalidCastException"/> will occur.</para> + /// <para>May return null if the <paramref name="device"/> instance is an embedded device not yet associated with a <see cref="SsdpRootDevice"/> instance yet.</para> + /// <para>If <paramref name="device"/> is an instance of <see cref="SsdpRootDevice"/> (or derives from it), returns the same instance cast to <see cref="SsdpRootDevice"/>.</para> + /// </remarks> + /// <returns>The <see cref="SsdpRootDevice"/> instance associated with the device instance specified, or null otherwise.</returns> + /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="device"/> is null.</exception> + /// <exception cref="System.InvalidCastException">Thrown if <paramref name="device"/> is not an instance of or dervied from either <see cref="SsdpRootDevice"/> or <see cref="SsdpEmbeddedDevice"/>.</exception> + public static SsdpRootDevice ToRootDevice(this SsdpDevice device) + { + if (device == null) throw new System.ArgumentNullException("device"); + + var rootDevice = device as SsdpRootDevice; + if (rootDevice == null) + rootDevice = ((SsdpEmbeddedDevice)device).RootDevice; + + return rootDevice; + } + } +} |
