private static void TestCollectionInstanceCreation(Type interfaceType) { object createdType = TypeService.BuildInterfaceImplementationType(interfaceType.FullName); Assert.True(createdType != null && createdType is Type); Type type = (Type)createdType; Assert.True(interfaceType.IsAssignableFrom(type)); }
public void TestMethodCreateInheritInterfaceImplementation() { object createdType = TypeService.BuildInterfaceImplementationType(typeof(ITestInterfaceExtended).FullName); Assert.True(createdType != null && createdType is Type); Type type = (Type)createdType; Assert.True(type.GetInterface(typeof(ITestInterfaceExtended).FullName) != null); }
public Type GetInterfaceImplementationType(string interfaceType) { if (interfaceTypeCache == null) { interfaceTypeCache = new Dictionary <string, Type>(); } Type implementationType = null; if (!interfaceTypeCache.TryGetValue(interfaceType, out implementationType)) { Type interfType; if (TypeService.TryGetTypeByName(interfaceType, out interfType)) { // check if a special sub type mapping resolver is registered if (exposedSubInterfaceTypeMappingInterfToClass != null) { Type exposedType; if (exposedSubInterfaceTypeMappingInterfToClass.TryGetValue(interfType, out exposedType)) { return(exposedType); } } // check if a local export is present for the type object instance; if (TryGetExport(interfType, out instance)) { return(instance.GetType()); } else { // No implementation found // Try auto generate type Type autoGeneratedType = TypeService.BuildInterfaceImplementationType(interfaceType); if (autoGeneratedType != null) { interfaceTypeCache[interfaceType] = autoGeneratedType; return(autoGeneratedType); } else { throw new Exception("Unable to auto generate a class implemenation for the interface \"" + interfaceType + "\"! Provide a local implementation."); } } } else { throw new TypeLoadException($"Coult not load type {interfaceType}!"); } } return(implementationType); }