public ConvClassInterfaceExternal(ConverterInfo info, TypeInfo typeInfo, Type managedType, ConverterAssemblyInfo converterAssemblyInfo) { m_typeInfo = typeInfo; m_managedType = managedType; info.RegisterType(managedType, this); // // Associate the default interface with the class interface // TypeInfo defaultInterfaceTypeInfo; if (converterAssemblyInfo.ClassInterfaceMap.GetExclusiveDefaultInterfaceForCoclass(typeInfo, out defaultInterfaceTypeInfo)) { IConvInterface convInterface = info.GetTypeRef(ConvType.Interface, defaultInterfaceTypeInfo) as IConvInterface; convInterface.AssociateWithExclusiveClassInterface(this); } }
public ConvCoClassExternal(ConverterInfo info, TypeInfo typeInfo, Type managedType, ConverterAssemblyInfo converterAssemblyInfo) { m_typeInfo = typeInfo; m_managedType = managedType; info.RegisterType(managedType, this); TypeInfo defaultTypeInfo = ConvCommon.GetDefaultInterface(ConvCommon.GetAlias(typeInfo)); if (defaultTypeInfo != null) { m_defaultInterface = info.GetTypeRef(ConvType.Interface, defaultTypeInfo) as IConvInterface; } }
private bool ResolveInternal(TypeInfo type, ConvType convType, out IConvBase convBase) { IConvBase ret = null; // See if it is already mapped if (!m_symbolTable.TryGetValue(GetInternalEncodedManagedName(type, convType), out ret)) { TypeLib typeLib = type.GetContainingTypeLib(); Guid libid; using (TypeLibAttr libAttr = typeLib.GetLibAttr()) { libid = libAttr.guid; } // See if this is defined in a different type library if (libid != m_libid) { ConverterAssemblyInfo converterAssemblyInfo = null; // See if we have not already imported this assembly if (!m_typeLibMappingTable.TryGetValue(libid, out converterAssemblyInfo)) { Assembly assembly = null; string asmName = typeLib.GetCustData(CustomAttributeGuids.GUID_ExportedFromComPlus) as string; if (asmName != null) { try { assembly = Assembly.ReflectionOnlyLoad(asmName); } catch (Exception) { } } if (assembly == null) { try { assembly = m_resolver.ResolveRef(typeLib.GetTypeLib()); } catch (TlbImpResolveRefFailWrapperException) { // Avoid wrapping wrapper with wrapper exception throw; } catch (Exception ex) { throw new TlbImpResolveRefFailWrapperException(ex); } } if (assembly == null) { // null means that the resolver has failed and we should skip this failure and continue with the next type throw new TlbImpInvalidTypeConversionException(type); } converterAssemblyInfo = new ConverterAssemblyInfo(this, assembly, typeLib); m_typeLibMappingTable.Add(libid, converterAssemblyInfo); } string expectedName; Type convertedType = converterAssemblyInfo.ResolveType(type, convType, out expectedName); if (convertedType == null) { throw new TlbImpGeneralException( Resource.FormatString("Err_CanotFindReferencedType", expectedName, converterAssemblyInfo.Assembly.FullName), ErrorCode.Err_CanotFindReferencedType); } else { // Create external IConvBase instance switch (convType) { case ConvType.Interface: ret = new ConvInterfaceExternal(this, type, convertedType, converterAssemblyInfo); break; case ConvType.Enum: ret = new ConvEnumExternal(this, type, convertedType); break; case ConvType.Struct: ret = new ConvStructExternal(this, type, convertedType); break; case ConvType.Union: ret = new ConvUnionExternal(this, type, convertedType); break; case ConvType.ClassInterface: Debug.Assert(false, "Only ConvCoClassExternal can create ConvClassInterfaceExternal"); break; case ConvType.EventInterface: Debug.Assert(false, "We should not reference a external event interface!"); break; case ConvType.CoClass: ret = new ConvCoClassExternal(this, type, convertedType, converterAssemblyInfo); break; } } } } convBase = ret; return(ret != null); }