/// <summary> /// Determines if the PluggedType can be upcast to the pluginType /// </summary> /// <param name="pluginType"></param> /// <param name="pluggedType"></param> /// <returns></returns> public static bool CanBeCastTo(this Type pluggedType, Type pluginType) { if (pluggedType == null) { return(false); } if (pluggedType == pluginType) { return(true); } if (pluginType.IsOpenGeneric()) { return(GenericsPluginGraph.CanBeCast(pluginType, pluggedType)); } if (IsOpenGeneric(pluggedType)) { return(false); } return(pluginType.GetTypeInfo().IsAssignableFrom(pluggedType.GetTypeInfo())); }
/// <summary> /// Determines if the pluggedType can be upcast to the pluginType /// </summary> /// <param name="pluginType"></param> /// <param name="pluggedType"></param> /// <returns></returns> public static bool CanBeCastTo(this Type pluggedType, Type pluginType) { if (pluggedType == null) { return(false); } if (pluggedType.IsInterface || pluggedType.IsAbstract) { return(false); } if (pluginType.IsOpenGeneric()) { return(GenericsPluginGraph.CanBeCast(pluginType, pluggedType)); } if (IsOpenGeneric(pluggedType)) { return(false); } return(pluginType.IsAssignableFrom(pluggedType)); }
public void Process(Type type, Registry registry) { if (!type.IsConcrete()) { return; } var interfaceTypes = type.FindInterfacesThatClose(typeof(BaseService <>)); foreach (var closedGenericType in interfaceTypes) { if (GenericsPluginGraph.CanBeCast(closedGenericType, type)) { registry.For(closedGenericType).Singleton().Use(type).Named(type.Name); } } }
private void assertCanNotBeCast(Type pluginType, Type TPluggedType) { Assert.IsFalse(GenericsPluginGraph.CanBeCast(pluginType, TPluggedType)); }
private void assertCanNotBeCast(Type pluginType, Type TPluggedType) { GenericsPluginGraph.CanBeCast(pluginType, TPluggedType).ShouldBeFalse(); }
public void SmokeTestCanBeCaseWithImplementationOfANonGenericInterface() { GenericsPluginGraph.CanBeCast(typeof(ITarget <,>), typeof(DisposableTarget <,>)).ShouldBeTrue(); }
private void assertCanBeCast(Type pluginType, Type pluggedType) { Assert.IsTrue(GenericsPluginGraph.CanBeCast(pluginType, pluggedType)); }