Example #1
0
            /// <summary>
            /// Resolves a reference during the exporting process. This means that the
            /// type library references the type library in another assembly. We must
            /// call back our <see cref="TypeLibHelper"/> to do this.
            /// </summary>
            /// <param name="assembly">Assembly to resolve.</param>
            /// <returns>Type library for the specified <paramref name="assembly"/>.
            /// Must implement the <see cref="ITypeLib"/> interface.</returns>
            /// <exception cref="ArgumentNullException"><paramref name="assembly"/>
            /// is <c>null</c>.</exception>
            public object ResolveRef(Assembly assembly)
            {
                ITypeLib tlb = null;

                // Validate input.
                if (assembly == null)
                {
                    throw new ArgumentNullException("assembly");
                }

                // We'll export the type lib next to the assembly.
                string assemblyName = assembly.GetName().Name;
                string typeLibName  = Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(
                                                                            AssemblyTools.GetAssemblyPath(assembly)), assemblyName), ".tlb");

                // Log recursive references in verbose mode.
                parent.console.Verbose.WriteLine("Recursively exporting and registering type " +
                                                 "library of assembly \"{0}\" to \"{1}\".", assemblyName, typeLibName);

                // Call back parent to export and register the type lib.
                tlb = parent.ExportTypeLibrary(assembly, typeLibName);
                parent.RegisterTypeLibrary(tlb, typeLibName);

                Debug.Assert(tlb != null);
                return(tlb);
            }
Example #2
0
        /// <summary>
        /// Called when the user passes the <c>/tlb</c> argument. If needed, exports
        /// the assembly to the specified type library, then registers the type library.
        /// </summary>
        private void ExportAndRegisterTypeLibrary()
        {
            Debug.Assert(prms.typeLibrary != null);

            // If the tlb is in the assembly, register it right away.
            // Otherwise, export and register it, which could cause
            // recursive registrations.
            TypeLibHelper tlbHelper = new TypeLibHelper(console, prms);

            if (String.Compare(prms.typeLibrary, prms.assemblyName, true) == 0)
            {
                tlbHelper.RegisterTypeLibrary(prms.typeLibrary);
            }
            else
            {
                tlbHelper.ExportAndRegisterTypeLibrary(assembly, prms.typeLibrary);
            }
        }