Example #1
0
        /// <summary>
        /// Uses <see cref="System.Reflection.Assembly.Load(AssemblyName)"/>
        /// to load an <see cref="System.Reflection.Assembly"/> and then the attendant
        /// <see cref="System.Type"/> referred to by the <paramref name="typeInfo"/>
        /// parameter.
        /// </summary>
        /// <param name="typeInfo">
        /// The assembly and type to be loaded.
        /// </param>
        /// <returns>
        /// A <see cref="System.Type"/>, or <see lang="null"/>.
        /// </returns>
        /// <exception cref="System.Exception">
        /// <see cref="System.Reflection.Assembly.Load(AssemblyName)"/>
        /// </exception>
        private static Type LoadTypeDirectlyFromAssembly(TypeAssemblyHolder typeInfo)
        {
            Type resolvedType = null;

            var assembly = AssemblyResolver.Resolve(typeInfo.AssemblyName);

            if (assembly != null)
            {
                resolvedType = assembly.GetType(typeInfo.TypeName, true, true);
            }

            return(resolvedType);
        }
Example #2
0
        /// <summary>
        /// Uses <see cref="System.Reflection.Assembly.GetEntryAssembly().GetReferencedAssemblies()"/>
        /// to load the attendant <see cref="System.Type"/> referred to by
        /// the <paramref name="typeInfo"/> parameter.
        /// </summary>
        /// <param name="typeInfo">
        /// The type to be loaded.
        /// </param>
        /// <returns>
        /// A <see cref="System.Type"/>, or <see lang="null"/>.
        /// </returns>
        private static Type LoadTypeByIteratingOverAllLoadedAssemblies(TypeAssemblyHolder typeInfo)
        {
            Type resolvedType = null;

            var anames = Assembly.GetEntryAssembly().GetReferencedAssemblies();

            foreach (var aname in Assembly.GetEntryAssembly().GetReferencedAssemblies())
            {
                var assembly = Assembly.Load(aname);
                resolvedType = assembly.GetType(typeInfo.TypeName, false, false);
                if (resolvedType != null)
                {
                    break;
                }
            }

            return(resolvedType);
        }