Exemple #1
0
        public static MarkdownableType[] Load(string dllPath, List <string> whitelist)
        {
            string 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);

            MarkdownableType[] markdownableTypes = new[] { Assembly.LoadFrom(dllPath) }
            .SelectMany(x => {
                try {
                    return(x.GetTypes());
                }
                catch (ReflectionTypeLoadException ex) {
                    return(ex.Types.Where(t => t != null));
                }
                catch {
                    return(Type.EmptyTypes);
                }
            })
            .Where(x => x != null)                                            // Filter null types
            .Where(x => whitelist == null || whitelist.Contains(x.Namespace)) // Filter namespace by whitelist
            .Where(x => x.IsPublic && !typeof(Delegate).IsAssignableFrom(x) && !x.GetCustomAttributes <ObsoleteAttribute>().Any())
            .Select(x => new MarkdownableType(x, commentsLookup))
            .ToArray();


            return(markdownableTypes);
        }
        public static MarkdownableType[] Load(string dllPath, string namespaceMatch)
        {
            var xmlPath = Path.Combine(Directory.GetParent(dllPath).FullName, Path.GetFileNameWithoutExtension(dllPath) + ".xml");

            var assembly = Assembly.LoadFrom(dllPath);

            //var aType = assembly.GetType("System.Reactive.Subjects.Subject`1");
            //var methods = aType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.InvokeMethod);
            //var methods = aType.GetRuntimeMethods();

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

            var namespaceRegex =
                !string.IsNullOrEmpty(namespaceMatch) ? new Regex(namespaceMatch) : null;

            var markdownableTypes = new[] { assembly }
            .SelectMany(x =>
            {
                try
                {
                    return(x.GetTypes());
                }
                catch (ReflectionTypeLoadException ex)
                {
                    return(ex.Types.Where(t => t != null));
                }
                catch
                {
                    return(Type.EmptyTypes);
                }
            })
            .Where(x => x != null)
            .Where(x => x.IsPublic && !typeof(Delegate).IsAssignableFrom(x) /* && !x.GetCustomAttributes<ObsoleteAttribute>().Any()*/)
            .Where(x => IsRequiredNamespace(x, namespaceRegex))
            .Select(x => new MarkdownableType(x, commentsLookup))
            .ToArray();


            return(markdownableTypes);
        }
        public static MarkdownableType[] Load(string dllPath, string namespaceMatch)
        {
            string 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)), namespaceMatch);
            }
            ILookup <string, XmlDocumentComment> commentsLookup = comments.ToLookup(x => x.ClassName);

            Regex namespaceRegex =
                !string.IsNullOrEmpty(namespaceMatch) ? new Regex(namespaceMatch) : null;

            MarkdownableType[] markdownableTypes = new[] { Assembly.LoadFrom(dllPath) }
            .SelectMany(x =>
            {
                try
                {
                    return(x.GetTypes());
                }
                catch (ReflectionTypeLoadException ex)
                {
                    return(ex.Types.Where(t => t != null));
                }
                catch
                {
                    return(Type.EmptyTypes);
                }
            })
            .Where(x => x != null)
            .Where(x => x.IsPublic && !typeof(Delegate).IsAssignableFrom(x) && !x.GetCustomAttributes <ObsoleteAttribute>().Any())
            .Where(x => IsRequiredNamespace(x, namespaceRegex))
            .Select(x => new MarkdownableType(x, commentsLookup))
            .ToArray();


            return(markdownableTypes);
        }
        public static MarkdownableType[] Load(string dllPath, string namespaceMatch)
        {
            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)), namespaceMatch);
            }
            var commentsLookup = comments.ToLookup(x => x.ClassName);

            var namespaceRegex =
                !string.IsNullOrEmpty(namespaceMatch) ? new Regex(namespaceMatch) : null;


            IEnumerable <Type> TypesSelector(Type type)
            {
                var types    = type.GetNestedTypes();
                var typeList = new List <Type>
                {
                    type
                };

                if (types.Length == 0)
                {
                    return(typeList);
                }
                typeList.AddRange(types.SelectMany(TypesSelector).ToArray());
                return(typeList);
            }

            IEnumerable <Type> AssemblyTypesSelector(Assembly x)
            {
                try
                {
                    var types = x.GetTypes().SelectMany(TypesSelector);
                    return(types);
                }
                catch (ReflectionTypeLoadException ex)
                {
                    return(ex.Types.Where(t => t != null));
                }
                catch
                {
                    return(Type.EmptyTypes);
                }
            }

            bool NotNullPredicate(Type x)
            {
                return(x != null);
            }

            bool NamespaceFilterPredicate(Type x)
            {
                var _IsRequiredNamespace = IsRequiredNamespace(x, namespaceRegex);

                return(_IsRequiredNamespace);
            }

            MarkdownableType markdownableTypeSelector(Type x)
            {
                MarkdownableType markdownableType = new MarkdownableType(x, commentsLookup);

                return(markdownableType);
            }

            bool OthersPredicate(Type x)
            {
                var IsPublic = x.IsPublic || (x.IsNested && x.IsNestedPublic);
                var IsAssignableFromDelegate = typeof(Delegate).IsAssignableFrom(x);
                var HaveObsoleteAttribute    = x.GetCustomAttributes <ObsoleteAttribute>().Any();

                return(IsPublic && !IsAssignableFromDelegate && !HaveObsoleteAttribute);
            }

            var dllAssemblys = new[] { Assembly.LoadFrom(dllPath) };

            var markdownableTypes = dllAssemblys
                                    .SelectMany(AssemblyTypesSelector)
                                    .Where(NotNullPredicate)
                                    .Where(OthersPredicate)
                                    .Where(NamespaceFilterPredicate)
                                    .Select(markdownableTypeSelector)
                                    .ToArray();


            return(markdownableTypes);
        }