Beispiel #1
0
        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);
                }

                if (Cache.ContainsKey(assemblyName.FullName))
                {
                    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);
            }
        }