From dca78b13411db96366dddfa0d68bb6d36d28ad14 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 29 Oct 2016 18:22:20 -0400 Subject: rework dlna project --- RSSDP/SsdpDeviceExtensions.cs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 RSSDP/SsdpDeviceExtensions.cs (limited to 'RSSDP/SsdpDeviceExtensions.cs') 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 +{ + /// + /// Extensions for and derived types. + /// + public static class SsdpDeviceExtensions + { + + /// + /// Returns the root device associated with a device instance derived from . + /// + /// The device instance to find the for. + /// + /// The must be or inherit from or , otherwise an will occur. + /// May return null if the instance is an embedded device not yet associated with a instance yet. + /// If is an instance of (or derives from it), returns the same instance cast to . + /// + /// The instance associated with the device instance specified, or null otherwise. + /// Thrown if is null. + /// Thrown if is not an instance of or dervied from either or . + 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; + } + } +} -- cgit v1.2.3