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;
}
}
}