LinFu.Proxy.InterfaceExtractor.GetInterfaces C# (CSharp) Method

GetInterfaces() public method

Determines which interfaces a given type should implement.
public GetInterfaces ( Type currentType, HashSet interfaceList ) : void
currentType System.Type 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);
            }
        }

Usage Example

Exemplo n.º 1
0
        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);
        }
All Usage Examples Of LinFu.Proxy.InterfaceExtractor::GetInterfaces
InterfaceExtractor