コード例 #1
0
        /// <summary>
        /// Resolves this command line metadata reference to a <see cref="MetadataReference"/> using given file resolver and metadata provider.
        /// </summary>
        /// <exception cref="BadImageFormatException">If the PE image format is invalid and <paramref name="diagnosticsOpt"/> is null.</exception>
        /// <exception cref="FileNotFoundException">If the Metadata file could not be found and <paramref name="diagnosticsOpt"/> is null.</exception>
        /// <exception cref="IOException">If error reading the file from disk and <paramref name="diagnosticsOpt"/> is null.</exception>
        /// <remarks>
        /// NOTE: Other exceptions, apart from those mentioned above, may be generated by the fileResolver or the metadata provider. These are not handled by this method.
        /// </remarks>
        /// <param name="fileResolver">The file resolver to use for assembly name and relative path resolution.</param>
        /// <param name="metadataProvider">Uses to create metadata references from resolved full paths.</param>
        /// <param name="diagnosticsOpt">Optional diagnostics list for storing diagnostics.</param>
        /// <param name="messageProviderOpt">Optional <see cref="CommonMessageProvider"/> for generating diagnostics.</param>
        /// <returns>Returns resolved metadata reference or <see cref="UnresolvedMetadataReference"/>.</returns>
        internal MetadataReference Resolve(FileResolver fileResolver, MetadataReferenceProvider metadataProvider, List <DiagnosticInfo> diagnosticsOpt, CommonMessageProvider messageProviderOpt)
        {
            Debug.Assert(fileResolver != null);
            Debug.Assert(metadataProvider != null);

            string path;

            if (this.IsAssemblyName)
            {
                path = fileResolver.ResolveAssemblyName(this.reference);
                if (path == null)
                {
                    if (diagnosticsOpt != null)
                    {
                        diagnosticsOpt.Add(new DiagnosticInfo(messageProviderOpt, messageProviderOpt.ERR_MetadataFileNotFound, this.reference));
                    }

                    return(new UnresolvedMetadataReference(this.reference, this.properties));
                }
            }
            else
            {
                path = this.reference;
            }

            // use search paths and base path of the resolver - usually these are the same as the paths stored on the arguments:
            string fullPath = fileResolver.ResolveMetadataFileChecked(path, baseFilePath: null);

            if (fullPath == null)
            {
                if (diagnosticsOpt != null)
                {
                    diagnosticsOpt.Add(new DiagnosticInfo(messageProviderOpt, messageProviderOpt.ERR_MetadataFileNotFound, this.reference));
                }

                return(new UnresolvedMetadataReference(this.reference, this.properties));
            }
            else
            {
                return(ResolveMetadataFile(fullPath, this.properties, metadataProvider, this.reference, diagnosticsOpt, messageProviderOpt));
            }
        }
コード例 #2
0
        /// <summary>
        /// Resolves this command line analyzer path to a <see cref="IEnumerable{IDiagnosticAnalyzer}"/> using given file resolver.
        /// </summary>
        /// <param name="fileResolver">The file resolver to use for assembly name and relative path resolution.</param>
        /// <param name="diagnosticsOpt">Optional diagnostics list for storing diagnostics.</param>
        /// <param name="messageProviderOpt">Optional <see cref="CommonMessageProvider"/> for generating diagnostics.</param>
        /// <returns>Returns null if the path is invalid. Otherwise returns the list of analyzer factories from the dll.</returns>
        internal IEnumerable <IDiagnosticAnalyzer> Resolve(FileResolver fileResolver, List <DiagnosticInfo> diagnosticsOpt, CommonMessageProvider messageProviderOpt)
        {
            Debug.Assert(fileResolver != null);

            string fullPath = fileResolver.ResolveMetadataFileChecked(this.analyzer, baseFilePath: null);

            if (fullPath == null)
            {
                if (diagnosticsOpt != null)
                {
                    diagnosticsOpt.Add(new DiagnosticInfo(messageProviderOpt, messageProviderOpt.ERR_MetadataFileNotFound, this.analyzer));
                }

                return(null);
            }
            else
            {
                return(ResolveAnalyzers(fullPath, this.analyzer, diagnosticsOpt, messageProviderOpt));
            }
        }