Esempio n. 1
0
        private static bool TryGetVisibility(string value, out DocumentationVisibility visibility)
        {
            if (!Enum.TryParse(value.Replace("-", ""), ignoreCase: true, out visibility))
            {
                WriteLine($"Unknown visibility '{value}'.");
                return(false);
            }

            return(true);
        }
        public DocumentationModel(
            Compilation compilation,
            IEnumerable <IAssemblySymbol> assemblies,
            DocumentationVisibility visibility = DocumentationVisibility.Publicly,
            IEnumerable <string> additionalXmlDocumentationPaths = null)
        {
            Compilation = compilation;
            Assemblies  = ImmutableArray.CreateRange(assemblies);
            Visibility  = visibility;

            _isVisible         = GetIsVisible();
            _symbolData        = new Dictionary <ISymbol, SymbolDocumentationData>();
            _xmlDocumentations = new Dictionary <IAssemblySymbol, XmlDocumentation>();

            if (additionalXmlDocumentationPaths != null)
            {
                _additionalXmlDocumentationPaths = additionalXmlDocumentationPaths.ToImmutableArray();
            }

            Func <ISymbol, bool> GetIsVisible()
            {
                switch (visibility)
                {
                case DocumentationVisibility.Publicly:
                    return(f => f.IsPubliclyVisible());

                case DocumentationVisibility.PubliclyOrInternally:
                    return(f => f.IsPubliclyOrInternallyVisible());

                case DocumentationVisibility.All:
                    return(_ => true);

                default:
                    throw new ArgumentException($"Unknown enum value '{visibility}'.", nameof(visibility));
                }
            }
        }
Esempio n. 3
0
        private static DocumentationModel CreateDocumentationModel(IEnumerable <string> assemblyReferences, IEnumerable <string> assemblies, DocumentationVisibility visibility, IEnumerable <string> additionalXmlDocumentationPaths = null)
        {
            var references = new List <PortableExecutableReference>();

            foreach (string path in assemblyReferences.SelectMany(f => GetAssemblyReferences(f)))
            {
                if (path == null)
                {
                    return(null);
                }

                references.Add(MetadataReference.CreateFromFile(path));
            }

            foreach (string assemblyPath in assemblies)
            {
                if (!TryGetReference(references, assemblyPath, out PortableExecutableReference reference))
                {
                    if (File.Exists(assemblyPath))
                    {
                        reference = MetadataReference.CreateFromFile(assemblyPath);
                        references.Add(reference);
                    }
                    else
                    {
                        WriteLine($"Assembly not found: '{assemblyPath}'.");
                        return(null);
                    }
                }
            }

            CSharpCompilation compilation = CSharpCompilation.Create(
                "",
                syntaxTrees: default(IEnumerable <SyntaxTree>),
                references: references,
                options: default(CSharpCompilationOptions));

            return(new DocumentationModel(
                       compilation,
                       assemblies.Select(assemblyPath =>
            {
                TryGetReference(references, assemblyPath, out PortableExecutableReference reference);
                return (IAssemblySymbol)compilation.GetAssemblyOrModuleSymbol(reference);
            }),
                       visibility: visibility,
                       additionalXmlDocumentationPaths: additionalXmlDocumentationPaths));
        }