public static MarkdownableSharpType[] Load(string dllPath, string pattern, ILogger logger)
        {
            var xmlPath = Path.Combine(Directory.GetParent(dllPath).FullName, Path.GetFileNameWithoutExtension(dllPath) + ".xml");

            XmlDocumentComment[] comments = new XmlDocumentComment[0];
            if (File.Exists(xmlPath))
            {
                comments = VSDocParser.ParseXmlComment(XDocument.Parse(File.ReadAllText(xmlPath)));
            }
            var commentsLookup = comments.ToLookup(x => x.ClassName);

            try {
                var assembly = Assembly.LoadFrom(dllPath);

                Type[] types = Type.EmptyTypes;

                try {
                    types = assembly.GetTypes();
                }
                catch (ReflectionTypeLoadException ex) {
                    types = ex.Types.Where(t => t != null).ToArray();
                }

                return(types
                       .Where(x => x != null)
                       .Where(x => x.IsPublic && !typeof(Delegate).IsAssignableFrom(x) && !x.GetCustomAttributes <ObsoleteAttribute>().Any())
                       .Where(x => IsRequiredNamespace(x, pattern))
                       .Select(x => new MarkdownableSharpType(x, commentsLookup))
                       .ToArray());
            }
            catch (Exception ex) {
                logger.LogWarning("Could not load assembly. \n" + ex.Message);
                return(Array.Empty <MarkdownableSharpType>());
            }
        }
Exemplo n.º 2
0
        public static MarkdownableSharpType[] LoadFromAssembly(CSharpLibrary library, string dllPath, string pattern, ILogger logger)
        {
            var xmlPath = Path.Combine(Directory.GetParent(dllPath).FullName, Path.GetFileNameWithoutExtension(dllPath) + ".xml");

            XmlDocumentComment[] comments = new XmlDocumentComment[0];
            if (File.Exists(xmlPath))
            {
                comments = VSDocParser.ParseXmlComment(XDocument.Parse(File.ReadAllText(xmlPath)));
            }
            var commentsLookup = comments.ToLookup(x => x.ClassName);

            try {
                var assembly = AssemblyDefinition.ReadAssembly(dllPath);
                var types    = assembly.Modules.SelectMany(m => m.Types);

                return(types
                       .Where(x => x != null)
                       .Where(x => x.IsPublic && !x.IsDelegate() && !x.HasObsoleteAttribute())
                       .Where(x => IsRequiredNamespace(x, pattern))
                       .Select(x => new MarkdownableSharpType(library, x, comments.Where(c => c.ClassName == x.FullName)))
                       .ToArray());
            }
            catch (Exception ex) {
                logger.LogWarning("Could not load assembly. \n" + ex.Message);
                return(Array.Empty <MarkdownableSharpType>());
            }
        }