public GetInterfaces ( |
||
currentType | The base type that holds the list of interfaces to implement. | |
interfaceList | HashSet |
The list of interfaces already being implemented. |
return | void |
public void GetInterfaces(Type currentType, HashSet<Type> interfaceList)
{
var interfaces = currentType.GetInterfaces();
if (interfaces == null || interfaces.Length == 0)
return;
foreach (var current in interfaces)
{
if (interfaceList.Contains(current))
continue;
interfaceList.Add(current);
GetInterfaces(current, interfaceList);
}
}
public void InterfaceExtractorShouldReturnTheCorrectResults() { var baseType = typeof (SampleClass); var extractor = new InterfaceExtractor(); var interfaces = new HashSet<Type>(); extractor.GetInterfaces(baseType, interfaces); Assert.IsTrue(interfaces.Contains(typeof (ISampleService))); Assert.IsTrue(interfaces.Contains(typeof (ISampleGenericService<int>))); // The result list must only contain interface types var nonInterfaceTypes = from t in interfaces where !t.IsInterface select t; Assert.IsTrue(nonInterfaceTypes.Count() == 0); }