Search This Blog

Thursday, January 21, 2016

Get all IP Addresses from devices attached to the machine C#

C# > System.Net > Dns > IPHostEntry > AddressList

AddressList gets or sets a list of IP addresses that are associated with a host.

Example

Get all IP Addresses from devices attached to the machine 


string hostName = Dns.GetHostName();
IPHostEntry ipHostEntry = Dns.GetHostEntry(hostName);
foreach (IPAddress item in ipHostEntry.AddressList)
{
var IPAddress = item.ToString();
}






Tuesday, January 5, 2016

C# Unit test to check if the class implements an interface with IsInstanceOfType method

C# > Assert Class > IsInstanceOfType

This method verifies that the specified object is an instance of the specified type. 

Example

Test class implements a specific interface.

var result = typeof(MyClass).GetInterfaces()[0];

// Assert

Assert.IsInstanceOfType(typeof(IMyClass), result.GetType());