예제 #1
0
        /*
         * This private function provides implementation for the two public versions.
         * searchPath is a simicolon-delimited list of paths on which to search for pathModule.
         * If searchPath is null, pathModule must be a full path to the assembly.
         */
        private static ISymbolReader GetReaderForFile(SymbolBinder binder, string pathModule, string searchPath)
        {
            // First create the Metadata dispenser.
            object objDispenser;

            NativeMethods.CoCreateInstance(ref dispenserClassID, null, 1, ref dispenserIID, out objDispenser);

            // Now open an Importer on the given filename. We'll end up passing this importer straight
            // through to the Binder.
            object objImporter;
            IMetaDataDispenserPrivate dispenser = (IMetaDataDispenserPrivate)objDispenser;

            dispenser.OpenScope(pathModule, OPEN_READ, ref importerIID, out objImporter);

            IntPtr        importerPtr = IntPtr.Zero;
            ISymbolReader reader;

            try
            {
                // This will manually AddRef the underlying object, so we need to be very careful to Release it.
                importerPtr = Marshal.GetComInterfaceForObject(objImporter, typeof(IMetadataImportPrivateComVisible));

                reader = binder.GetReader(importerPtr, pathModule, searchPath);
            }
            finally
            {
                if (importerPtr != IntPtr.Zero)
                {
                    Marshal.Release(importerPtr);
                }
            }
            return(reader);
        }
예제 #2
0
        // Initialization routine that allows a customized writer object to be supplied
        private static ISymbolWriter2 InitializeWriterForFile(SymbolWriter writer, string pathModule, ref object emitter)
        {
            // If no emitter is provided, make one and return it.
            if (emitter == null)
            {
                // First get a dispenser
                object objDispenser;
                NativeMethods.CoCreateInstance(ref dispenserClassID, null, 1, ref dispenserIID, out objDispenser);
                Debug.Assert(objDispenser != null, "Dispenser is null.");

                // Now get an emitter
                IMetaDataDispenserPrivate dispenser = (IMetaDataDispenserPrivate)objDispenser;
                dispenser.OpenScope(pathModule, OPEN_WRITE, ref emitterIID, out emitter);
            }
            Debug.Assert(emitter != null, "Emitter is null.");

            // An emitter was provided, just use that one.
            writer.Initialize(emitter, pathModule, false);
            return(writer);
        }