示例#1
0
        /// <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()));
        }
示例#2
0
            /// <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);
            }
        }
    }
示例#4
0
 private void assertCanNotBeCast(Type pluginType, Type TPluggedType)
 {
     Assert.IsFalse(GenericsPluginGraph.CanBeCast(pluginType, TPluggedType));
 }
示例#5
0
 private void assertCanNotBeCast(Type pluginType, Type TPluggedType)
 {
     GenericsPluginGraph.CanBeCast(pluginType, TPluggedType).ShouldBeFalse();
 }
示例#6
0
 public void SmokeTestCanBeCaseWithImplementationOfANonGenericInterface()
 {
     GenericsPluginGraph.CanBeCast(typeof(ITarget <,>), typeof(DisposableTarget <,>)).ShouldBeTrue();
 }
示例#7
0
 private void assertCanBeCast(Type pluginType, Type pluggedType)
 {
     Assert.IsTrue(GenericsPluginGraph.CanBeCast(pluginType, pluggedType));
 }