diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-12-18 00:44:33 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-12-18 00:44:33 -0500 |
| commit | e7cebb91a73354dc3e0d0b6340c9fbd6511f4406 (patch) | |
| tree | 6f1c368c766c17b7514fe749c0e92e69cd89194a /RSSDP/SsdpDeviceExtensions.cs | |
| parent | 025905a3e4d50b9a2e07fbf4ff0a203af6604ced (diff) | |
| parent | aaa027f3229073e9a40756c3157d41af2a442922 (diff) | |
Merge pull request #2350 from MediaBrowser/beta
Beta
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 000000000..0ad710a6b --- /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; + } + } +} |
