/// <summary> /// When an (interop) assembly is loaded, we scan it to discover the GUIDs of COM interfaces so that we can /// associate the type definition with COM objects with that GUID. /// Since scanning all loaded assemblies can be expensive, in the future, we might consider a more explicit /// user binder to trigger scanning of COM types. /// </summary> public static void PublishComTypes(Assembly interopAssembly) { #if !SILVERLIGHT lock (_comTypeCache) { // We lock over the entire operation so that we can publish a consistent view foreach (Type type in AssemblyTypeNames.LoadTypesFromAssembly(interopAssembly, false)) { if (type.IsImport && type.IsInterface) { Type existing; if (_comTypeCache.TryGetValue(type.GUID, out existing)) { if (!existing.IsDefined(typeof(CoClassAttribute), false)) { // prefer the type w/ CoClassAttribute on it. Example: // MS.Office.Interop.Excel.Worksheet // vs // MS.Office.Interop.Excel._Worksheet // Worksheet defines all the interfaces that the type supports and has CoClassAttribute. // _Worksheet is just the interface for the worksheet. // // They both have the same GUID though. _comTypeCache[type.GUID] = type; } } else { _comTypeCache[type.GUID] = type; } } } } #endif }
protected void DiscoverAllTypes(Assembly assem) { // lock is held when this is called Assert.NotNull(assem); NamespaceTracker previousPackage = null; string previousFullNamespace = String.Empty; // Note that String.Empty is not a valid namespace foreach (TypeName typeName in AssemblyTypeNames.GetTypeNames(assem, _topPackage.DomainManager.Configuration.PrivateBinding)) { NamespaceTracker package; Debug.Assert(typeName.Namespace != String.Empty); if (typeName.Namespace == previousFullNamespace) { // We have a cache hit. We dont need to call GetOrMakePackageHierarchy (which generates // a fair amount of temporary substrings) package = previousPackage; } else { package = GetOrMakePackageHierarchy(assem, typeName.Namespace); previousFullNamespace = typeName.Namespace; previousPackage = package; } package.AddTypeName(typeName.Name, assem); } }
protected void DiscoverAllTypes(Assembly assem) { #if FULL NamespaceTracker previousPackage = null; string previousFullNamespace = String.Empty; // Note that String.Empty is not a valid namespace foreach (TypeName typeName in AssemblyTypeNames.GetTypeNames(assem)) { NamespaceTracker package; Debug.Assert(typeName.Namespace != String.Empty); if (typeName.Namespace == previousFullNamespace) { // We have a cache hit. We dont need to call GetOrMakePackageHierarchy (which generates // a fair amount of temporary substrings) package = previousPackage; } else { package = GetOrMakePackageHierarchy(assem, typeName.Namespace); previousFullNamespace = typeName.Namespace; previousPackage = package; } package.AddTypeName(typeName.Name, assem); } #endif }