コード例 #1
0
        /// <summary>
        /// Creates an instance of T of the specified type, and ensures it implements the required interface type.
        /// </summary>
        /// <typeparam name="T">Type of class to return.</typeparam>
        /// <param name="type">The type to try and load.</param>
        /// <param name="requiredInterface">The required interface that type must implement.</param>
        /// <returns>
        /// Null if the object could not be loaded.
        /// </returns>
        internal static T CreateInstanceWithRequiredInterface <T>(Type type, Type requiredInterface) where T : class
        {
            ITypeActivator typeActivator = typeResolver.GetTypeActivator(type);

            return(typeActivator.CreateInstanceWithRequiredInterface <T>(type, requiredInterface));
        }
コード例 #2
0
        /// <summary>
        /// Creates an instance of T from the specified typeName, and ensures it implements the required interface type.
        /// </summary>
        /// <typeparam name="T">Type of class to return.</typeparam>
        /// <param name="typeName">Name of the type to try and load.</param>
        /// <param name="requiredInterfaceTypeName">Name of the required interface that type must implement.</param>
        /// <returns>
        /// Null if the object could not be loaded.
        /// </returns>
        internal static T CreateInstanceWithRequiredInterface <T>(string typeName, string requiredInterfaceTypeName) where T : class
        {
            ITypeActivator typeActivator = typeResolver.GetTypeActivator(typeName);

            return(typeActivator.CreateInstanceWithRequiredInterface <T>(typeName, requiredInterfaceTypeName));
        }