private static async Task <XDocument> TryGetXmlDocumentAsync(AssemblyName assemblyName, string pathToXmlFile, bool useLock)
        {
            if (useLock)
            {
#if !LEGACY
                await _lock.WaitAsync();
#else
                _lock.Wait();
#endif
            }

            try
            {
                if (!Cache.ContainsKey(assemblyName.FullName))
                {
                    if (await DynamicApis.FileExistsAsync(pathToXmlFile).ConfigureAwait(false) == false)
                    {
                        Cache[assemblyName.FullName] = null;
                        return(null);
                    }

                    Cache[assemblyName.FullName] = await Task.Factory.StartNew(() => XDocument.Load(pathToXmlFile, LoadOptions.PreserveWhitespace)).ConfigureAwait(false);
                }

                return(Cache[assemblyName.FullName]);
            }
            finally
            {
                if (useLock)
                {
                    _lock.Release();
                }
            }
        }
        private static async Task <string> GetXmlDocumentationPathAsync(dynamic assembly)
        {
            try
            {
                if (assembly == null)
                {
                    return(null);
                }

                if (string.IsNullOrEmpty(assembly.Location))
                {
                    return(null);
                }

                var assemblyName = assembly.GetName();
                if (string.IsNullOrEmpty(assemblyName.Name))
                {
                    return(null);
                }

                var assemblyDirectory = DynamicApis.PathGetDirectoryName((string)assembly.Location);
                var path = DynamicApis.PathCombine(assemblyDirectory, (string)assemblyName.Name + ".xml");
                if (await DynamicApis.FileExistsAsync(path).ConfigureAwait(false))
                {
                    return(path);
                }

                if (ReflectionExtensions.HasProperty(assembly, "CodeBase"))
                {
                    path = DynamicApis.PathCombine(DynamicApis.PathGetDirectoryName(assembly.CodeBase
                                                                                    .Replace("file:///", string.Empty)), assemblyName.Name + ".xml")
                           .Replace("file:\\", string.Empty);

                    if (await DynamicApis.FileExistsAsync(path).ConfigureAwait(false))
                    {
                        return(path);
                    }
                }

                var currentDomain = Type.GetType("System.AppDomain").GetRuntimeProperty("CurrentDomain").GetValue(null);
                if (currentDomain.HasProperty("BaseDirectory"))
                {
                    var baseDirectory = currentDomain.TryGetPropertyValue("BaseDirectory", "");
                    path = DynamicApis.PathCombine(baseDirectory, assemblyName.Name + ".xml");
                    if (await DynamicApis.FileExistsAsync(path).ConfigureAwait(false))
                    {
                        return(path);
                    }

                    return(DynamicApis.PathCombine(baseDirectory, "bin\\" + assemblyName.Name + ".xml"));
                }

                return(null);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #3
0
        private static async Task <XDocument> TryGetXmlDocumentAsync(AssemblyName assemblyName, string pathToXmlFile)
        {
            if (!Cache.ContainsKey(assemblyName.FullName))
            {
                if (await DynamicApis.FileExistsAsync(pathToXmlFile).ConfigureAwait(false) == false)
                {
                    Cache[assemblyName.FullName] = null;
                    return(null);
                }

                Cache[assemblyName.FullName] = await Task.Factory.StartNew(() => XDocument.Load(pathToXmlFile, LoadOptions.PreserveWhitespace)).ConfigureAwait(false);
            }

            return(Cache[assemblyName.FullName]);
        }
        /// <summary>Returns the contents of the "returns" or "param" XML documentation tag for the specified parameter.</summary>
        /// <param name="parameter">The reflected parameter or return info.</param>
        /// <param name="pathToXmlFile">The path to the XML documentation file.</param>
        /// <returns>The contents of the "returns" or "param" tag.</returns>
        public static async Task <XElement> GetXmlDocumentationAsync(this ParameterInfo parameter, string pathToXmlFile)
        {
            try
            {
                if (pathToXmlFile == null || DynamicApis.SupportsXPathApis == false || DynamicApis.SupportsFileApis == false || DynamicApis.SupportsPathApis == false)
                {
                    return(null);
                }

                var assemblyName = parameter.Member.Module.Assembly.GetName();

#if !LEGACY
                await _lock.WaitAsync();
#else
                _lock.Wait();
#endif
                try
                {
                    if (Cache.ContainsKey(assemblyName.FullName) && Cache[assemblyName.FullName] == null)
                    {
                        return(null);
                    }

                    if (await DynamicApis.FileExistsAsync(pathToXmlFile).ConfigureAwait(false) == false)
                    {
                        Cache[assemblyName.FullName] = null;
                        return(null);
                    }

                    if (!Cache.ContainsKey(assemblyName.FullName))
                    {
                        Cache[assemblyName.FullName] = await Task.Factory.StartNew(() => XDocument.Load(pathToXmlFile)).ConfigureAwait(false);
                    }

                    return(GetXmlDocumentation(parameter, Cache[assemblyName.FullName]));
                }
                finally
                {
                    _lock.Release();
                }
            }
            catch
            {
                return(null);
            }
        }