Exemplo n.º 1
0
        public static void Generate(string assemblyFile, string docdir)
        {
            if (assemblyFile == null)
            {
                throw new ArgumentNullException(nameof(assemblyFile));
            }
            if (assemblyFile.Length == 0)
            {
                throw new ArgumentException("assemblyFile is empty.");
            }
            if (docdir == null)
            {
                throw new ArgumentNullException(nameof(docdir));
            }
            if (docdir.Length == 0)
            {
                throw new ArgumentException("docdir is empty.");
            }
            var directory = Path.GetFullPath(docdir);

            assemblyFile = Path.GetFullPath(assemblyFile);
            var assemblyXml = Path.ChangeExtension(assemblyFile, ".xml");

            Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyFile));
            if (!File.Exists(assemblyFile))
            {
                // Exit early, not found
                throw new ArgumentException("Assembly file not found: " + assemblyFile);
            }
            if (!File.Exists(assemblyXml))
            {
                // Exit early, not found
                throw new ArgumentException("XML documentation not found: " +
                                            assemblyXml);
            }
            var asm = Assembly.LoadFrom(assemblyFile);

            Directory.CreateDirectory(directory);
            try {
                var xmldoc    = new XmlDoc(assemblyXml);
                var oldWriter = Console.Out;
                var visitor   = new TypeVisitor(directory);
                foreach (var t in asm.GetTypes())
                {
                    visitor.HandleTypeAndMembers(t, xmldoc);
                }
                visitor.Finish();
                var visitor2 = new SummaryVisitor(
                    Path.Combine(directory, "APIDocs.md"));
                foreach (var t in asm.GetTypes())
                {
                    visitor2.HandleType(t, xmldoc);
                }
                visitor2.Finish();
            } catch (IOException ex) {
                Console.WriteLine(ex.Message);
                return;
            }
        }
Exemplo n.º 2
0
        public void HandleMember(object info, XmlDoc xmldoc)
        {
            var isPublicOrProtected = false;
            var typeInfo            = info as Type;
            var methodInfo          = info as MethodInfo;
            var propertyInfo        = info as PropertyInfo;
            var fieldInfo           = info as FieldInfo;

            if (methodInfo != null)
            {
                isPublicOrProtected = methodInfo.IsPublic || methodInfo.IsFamily;
            }
            if (propertyInfo != null)
            {
                isPublicOrProtected = (propertyInfo.CanRead &&
                                       (propertyInfo.GetGetMethod().IsPublic ||
                                        propertyInfo.GetGetMethod().IsFamily)) ||
                                      (propertyInfo.CanWrite &&
                                       (propertyInfo.GetSetMethod().IsPublic ||
                                        propertyInfo.GetSetMethod().IsFamily));
            }
            if (fieldInfo != null)
            {
                isPublicOrProtected = fieldInfo.IsPublic || fieldInfo.IsFamily;
            }
            if (!isPublicOrProtected)
            {
                return;
            }
            string memberAnchor = MemberAnchor(info);

            this.memberFormats[memberAnchor] = FormatMember(info);
            if (!this.docs.ContainsKey(memberAnchor))
            {
                var docVisitor = new StringBuilder();
                this.docs[memberAnchor] = docVisitor;
            }
            string memberFullName = TypeNameUtil.XmlDocMemberName(info);
            var    summary        = SummaryVisitor.GetSummary(
                info as MemberInfo,
                xmldoc,
                memberFullName);

            if (summary == null)
            {
                Console.WriteLine("no summary for " + memberFullName);
            }
            else
            {
                this.docs[memberAnchor].Append(summary)
                .Append("\r\n");
            }
        }
Exemplo n.º 3
0
        public static void Generate(string assemblyFile, string docdir)
        {
            if (assemblyFile == null)
            {
                throw new ArgumentNullException("assemblyFile");
            }
            if (assemblyFile.Length == 0)
            {
                throw new ArgumentException("assemblyFile is empty.");
            }
            if (docdir == null)
            {
                throw new ArgumentNullException("docdir");
            }
            if (docdir.Length == 0)
            {
                throw new ArgumentException("docdir is empty.");
            }
            var directory = Path.GetFullPath(docdir);

            assemblyFile = Path.GetFullPath(assemblyFile);
            Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyFile));
            if (!File.Exists(assemblyFile))
            {
                // Exit early, not found
                return;
            }
            var assembly = Assembly.LoadFrom(assemblyFile);

            Directory.CreateDirectory(directory);
            try {
                var members   = DocReader.Read(assembly);
                var oldWriter = Console.Out;
                var visitor   = new TypeVisitor(directory);
                members.Accept(visitor);
                visitor.Finish();
                using (
                    var writer = new StreamWriter(
                        Path.Combine(directory, "APIDocs.md"),
                        false,
                        Encoding.UTF8)) {
                    var visitor2 = new SummaryVisitor(writer);
                    members.Accept(visitor2);
                    visitor2.Finish();
                }
            } catch (IOException ex) {
                Console.WriteLine(ex.Message);
                return;
            }
        }
Exemplo n.º 4
0
 public string GetSummary(string memberID)
 {
     if (!this.memberNodes.ContainsKey(memberID))
     {
         return(null);
     }
     else
     {
         var mn = this.memberNodes[memberID];
         var sb = new StringBuilder();
         foreach (var c in mn.GetChildren())
         {
             if (c.LocalName.Equals("summary", StringComparison.Ordinal))
             {
                 var sv = new SummaryVisitor();
                 sv.VisitNode(c);
                 sb.Append(sv.ToString()).Append("\r\n\r\n");
             }
         }
         var summary = sb.ToString();
         summary = Regex.Replace(summary, @"^\s+$", String.Empty);
         return(summary);
     }
 }