예제 #1
0
        private static Docs?ParseDocs(GeneratorExecutionContext context)
        {
            Docs?docs = null;

            if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.CsWin32InputDocPaths", out string?delimitedApiDocsPaths) &&
                !string.IsNullOrWhiteSpace(delimitedApiDocsPaths))
            {
                string[] apiDocsPaths = delimitedApiDocsPaths !.Split('|');
                if (apiDocsPaths.Length > 0)
                {
                    List <Docs> docsList = new(apiDocsPaths.Length);
                    foreach (string path in apiDocsPaths)
                    {
                        try
                        {
                            docsList.Add(Docs.Get(path));
                        }
                        catch (Exception e)
                        {
                            context.ReportDiagnostic(Diagnostic.Create(DocParsingError, null, path, e.Message));
                        }
                    }

                    docs = Docs.Merge(docsList);
                }
            }

            return(docs);
        }
예제 #2
0
파일: Docs.cs 프로젝트: ScriptBox21/CsWin32
        /// <summary>
        /// Loads docs from a file.
        /// </summary>
        /// <param name="docsPath">The messagepack docs file to read from.</param>
        /// <returns>An instance of <see cref="Docs"/> that accesses the documentation in the file specified by <paramref name="docsPath"/>.</returns>
        public static Docs Get(string docsPath)
        {
            lock (DocsByPath)
            {
                if (DocsByPath.TryGetValue(docsPath, out Docs? existing))
                {
                    return(existing);
                }
            }

            using FileStream docsStream = File.OpenRead(docsPath);
            var data = MessagePackSerializer.Deserialize <Dictionary <string, ApiDetails> >(docsStream);
            var docs = new Docs(data);

            lock (DocsByPath)
            {
                if (DocsByPath.TryGetValue(docsPath, out Docs? existing))
                {
                    return(existing);
                }

                DocsByPath.Add(docsPath, docs);
                return(docs);
            }
        }