コード例 #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));
            }
コード例 #3
0
    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));
 }