Extension method for getting the immediate interfaces on a Type

This commit is contained in:
Chris Cameron
2018-03-28 11:24:03 -04:00
parent fb6ee9d468
commit 1ac5e26992
2 changed files with 47 additions and 0 deletions

View File

@@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ICD.Common.Utils.Extensions;
using NUnit.Framework;
@@ -93,6 +95,20 @@ namespace ICD.Common.Utils.Tests.Extensions
Assert.IsTrue(baseTypes.Contains(typeof(object)));
}
[Test]
public void GetImmediateInterfacesTest()
{
Type[] interfaces = typeof(ICollection<int>).GetImmediateInterfaces().ToArray();
Assert.AreEqual(1, interfaces.Length);
Assert.AreEqual(typeof(IEnumerable<int>), interfaces[0]);
interfaces = typeof(IEnumerable<int>).GetImmediateInterfaces().ToArray();
Assert.AreEqual(1, interfaces.Length);
Assert.AreEqual(typeof(IEnumerable), interfaces[0]);
}
private interface C
{
}