/// <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(object cacheLock, object loadInfoToTypeLock, ConcurrentDictionary <TypeFilter, ConcurrentDictionary <AssemblyLoadInfo, AssemblyInfoToLoadedTypes> > cache, string typeName, AssemblyLoadInfo assembly) { // A given typefilter have been used on a number of assemblies, Based on the typefilter 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. ConcurrentDictionary <AssemblyLoadInfo, AssemblyInfoToLoadedTypes> loadInfoToType = null; lock (cacheLock) { if (!cache.TryGetValue(_isDesiredType, out loadInfoToType)) { loadInfoToType = new ConcurrentDictionary <AssemblyLoadInfo, AssemblyInfoToLoadedTypes>(); cache.TryAdd(_isDesiredType, loadInfoToType); } } // 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 = null; lock (loadInfoToTypeLock) { if (!loadInfoToType.TryGetValue(assembly, out typeNameToType)) { typeNameToType = new AssemblyInfoToLoadedTypes(_isDesiredType, assembly); loadInfoToType.TryAdd(assembly, typeNameToType); } } return(typeNameToType.GetLoadedTypeByTypeName(typeName)); }
/// <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(ConcurrentDictionary <Func <Type, object, bool>, 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. ConcurrentDictionary <AssemblyLoadInfo, AssemblyInfoToLoadedTypes> loadInfoToType = cache.GetOrAdd(_isDesiredType, (_) => new 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)); }
/// <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(object cacheLock, object loadInfoToTypeLock, ConcurrentDictionary<TypeFilter, ConcurrentDictionary<AssemblyLoadInfo, AssemblyInfoToLoadedTypes>> cache, string typeName, AssemblyLoadInfo assembly) { // A given typefilter have been used on a number of assemblies, Based on the typefilter 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. ConcurrentDictionary<AssemblyLoadInfo, AssemblyInfoToLoadedTypes> loadInfoToType = null; lock (cacheLock) { if (!cache.TryGetValue(_isDesiredType, out loadInfoToType)) { loadInfoToType = new ConcurrentDictionary<AssemblyLoadInfo, AssemblyInfoToLoadedTypes>(); cache.TryAdd(_isDesiredType, loadInfoToType); } } // 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 = null; lock (loadInfoToTypeLock) { if (!loadInfoToType.TryGetValue(assembly, out typeNameToType)) { typeNameToType = new AssemblyInfoToLoadedTypes(_isDesiredType, assembly); loadInfoToType.TryAdd(assembly, typeNameToType); } } return typeNameToType.GetLoadedTypeByTypeName(typeName); }