Example #1
0
 /// <summary>
 /// Loads the specified type if it exists in the given assembly. If the type name is fully qualified, then a match (if
 /// any) is unambiguous; otherwise, if there are multiple types with the same name in different namespaces, the first type
 /// found will be returned.
 /// </summary>
 /// <returns>The loaded type, or null if the type was not found.</returns>
 internal LoadedType ReflectionOnlyLoad
 (
     string typeName,
     AssemblyLoadInfo assembly
 )
 {
     return(GetLoadedType(s_cacheOfReflectionOnlyLoadedTypesByFilter, typeName, assembly));
 }
Example #2
0
            /// <summary>
            /// Given a type filter, and an assembly to load the type information from determine if a given type name is in the assembly or not.
            /// </summary>
            internal AssemblyInfoToLoadedTypes(TypeFilter typeFilter, AssemblyLoadInfo loadInfo)
            {
                ErrorUtilities.VerifyThrowArgumentNull(typeFilter, "typefilter");
                ErrorUtilities.VerifyThrowArgumentNull(loadInfo, "loadInfo");

                _isDesiredType        = typeFilter;
                _assemblyLoadInfo     = loadInfo;
                _typeNameToType       = new Concurrent.ConcurrentDictionary <string, Type>(StringComparer.OrdinalIgnoreCase);
                _publicTypeNameToType = new Dictionary <string, Type>(StringComparer.OrdinalIgnoreCase);
            }
Example #3
0
        /// <summary>
        /// Creates an instance of this class for the given type.
        /// </summary>
        /// <param name="type">The Type to be loaded</param>
        /// <param name="assemblyLoadInfo">Information used to load the assembly</param>
        /// <param name="loadedAssembly">The assembly which has been loaded, if any</param>
        internal LoadedType(Type type, AssemblyLoadInfo assemblyLoadInfo, Assembly loadedAssembly)
        {
            ErrorUtilities.VerifyThrow(type != null, "We must have the type.");
            ErrorUtilities.VerifyThrow(assemblyLoadInfo != null, "We must have the assembly the type was loaded from.");

            _type           = type;
            _assembly       = assemblyLoadInfo;
            _loadedAssembly = loadedAssembly;

            CheckForHardcodedSTARequirement();
            HasLoadInSeparateAppDomainAttribute();
            HasSTAThreadAttribute();
        }
Example #4
0
 /// <summary>
 /// Creates an instance of this class for the given type.
 /// </summary>
 internal LoadedType(Type type, AssemblyLoadInfo assemblyLoadInfo)
     : this(type, assemblyLoadInfo, null)
 {
 }
Example #5
0
        /// <summary>
        /// Loads the specified type if it exists in the given assembly. If the type name is fully qualified, then a match (if
        /// any) is unambiguous; otherwise, if there are multiple types with the same name in different namespaces, the first type
        /// found will be returned.
        /// </summary>
        private LoadedType GetLoadedType(Concurrent.ConcurrentDictionary <TypeFilter, Concurrent.ConcurrentDictionary <AssemblyLoadInfo, AssemblyInfoToLoadedTypes> > cache, string typeName, AssemblyLoadInfo assembly)
        {
            // A given type filter have been used on a number of assemblies, Based on the type filter we will get another dictionary which
            // will map a specific AssemblyLoadInfo to a AssemblyInfoToLoadedTypes class which knows how to find a typeName in a given assembly.
            Concurrent.ConcurrentDictionary <AssemblyLoadInfo, AssemblyInfoToLoadedTypes> loadInfoToType =
                cache.GetOrAdd(_isDesiredType, (_) => new Concurrent.ConcurrentDictionary <AssemblyLoadInfo, AssemblyInfoToLoadedTypes>());

            // Get an object which is able to take a typename and determine if it is in the assembly pointed to by the AssemblyInfo.
            AssemblyInfoToLoadedTypes typeNameToType =
                loadInfoToType.GetOrAdd(assembly, (_) => new AssemblyInfoToLoadedTypes(_isDesiredType, _));

            return(typeNameToType.GetLoadedTypeByTypeName(typeName));
        }