public void Should_return_the_generic_type_from_a_class() { IEnumerable <Type> types = InterfaceExtensions.GetClosingArguments(typeof(NonGenericSubClass), typeof(GenericBaseClass <>)); Assert.AreEqual(1, types.Count()); Assert.AreEqual(typeof(int), types.First()); }
public void Should_return_the_appropriate_generic_type_with_a_generic_base_class() { IEnumerable <Type> types = InterfaceExtensions.GetClosingArguments(typeof(NonGenericSubClass), typeof(IGeneric <>)); Assert.AreEqual(1, types.Count()); Assert.AreEqual(typeof(int), types.First()); }
Type CreateImplementation(Type interfaceType) { var typeInfo = interfaceType.GetTypeInfo(); if (!typeInfo.IsInterface) { throw new ArgumentException("Bus instance types can only be created for interfaces: " + interfaceType.Name, nameof(interfaceType)); } if (typeInfo.IsGenericType) { throw new ArgumentException("Bus instance types can not be generic: " + interfaceType.Name, nameof(interfaceType)); } if (!InterfaceExtensions.HasInterface <IBus>(typeInfo)) { throw new ArgumentException("Bus instance types must include the IBus interface: " + interfaceType.Name, nameof(interfaceType)); } return(GetModuleBuilderForType(interfaceType, moduleBuilder => CreateTypeFromInterface(moduleBuilder, interfaceType))); }
public void Should_not_have_closing_arguments_for_a_class_that_isnt_closed() { IEnumerable <Type> types = InterfaceExtensions.GetClosingArguments(typeof(SuperGenericBaseClass <>), typeof(IGeneric <>)); Assert.AreEqual(0, types.Count()); }