Esempio n. 1
0
        public void WhenPassedAnInvalidPath_Parse_TypeIsError()
        {
            CRefPath path = CRefPath.Parse("invalid string");

            Assert.AreEqual(CRefTypes.Error, path.PathType);
            Assert.AreEqual(string.Empty, path.ToString());
        }
Esempio n. 2
0
        private void WriteEntry(System.Xml.XmlWriter writer, ReflectedMember entryMember, string displayName, string type)
        {
            CRefPath       currentPath    = CRefPath.Create(entryMember);
            XmlCodeComment currentComment = this._xmlComments.GetComment(currentPath);

            writer.WriteStartElement("entry");
            writer.WriteAttributeString("id", entryMember.GetGloballyUniqueId().ToString());
            writer.WriteAttributeString("subId", string.Empty);
            writer.WriteAttributeString("type", type);
            writer.WriteAttributeString("visibility", ReflectionHelper.GetVisibility(entryMember));
            writer.WriteAttributeString("cref", currentPath.ToString());

            writer.WriteStartElement("name");
            writer.WriteString(displayName);
            writer.WriteEndElement();

            // find and output the summary
            if (currentComment != XmlCodeComment.Empty && currentComment.Elements != null)
            {
                XmlCodeElement summary = currentComment.Elements.Find(currentBlock => currentBlock is SummaryXmlCodeElement);
                if (summary != null)
                {
                    Serialize(summary, writer);
                }
            }
            writer.WriteEndElement();
        }
Esempio n. 3
0
        /// <summary>
        /// Renders the method XML to the <paramref name="writer."/>
        /// </summary>
        /// <param name="writer">The open valid writer to write to.</param>
        public override void Render(System.Xml.XmlWriter writer)
        {
            CRefPath       crefPath    = new CRefPath(_member);
            XmlCodeComment comment     = _xmlComments.GetComment(crefPath);
            string         displayName = _member.GetDisplayName(false);

            writer.WriteStartElement("member");
            writer.WriteAttributeString("id", AssociatedEntry.Key.ToString());
            writer.WriteAttributeString("subId", AssociatedEntry.SubKey);
            writer.WriteAttributeString("type", ReflectionHelper.GetType(_member));
            writer.WriteAttributeString("cref", crefPath.ToString());
            writer.WriteStartElement("name");
            writer.WriteAttributeString("safename", Exporter.CreateSafeName(displayName));
            writer.WriteString(_member.GetDisplayName(false));
            writer.WriteEndElement();

            writer.WriteStartElement("namespace");
            Entry namespaceEntry = AssociatedEntry.FindNamespace(_member.Type.Namespace);

            writer.WriteAttributeString("id", namespaceEntry.Key.ToString());
            writer.WriteAttributeString("name", namespaceEntry.SubKey);
            writer.WriteAttributeString("cref", $"N:{_member.Type.Namespace}");
            writer.WriteString(_member.Type.Namespace);
            writer.WriteEndElement();
            writer.WriteStartElement("assembly");
            writer.WriteAttributeString("file", System.IO.Path.GetFileName(_member.Assembly.FileName));
            writer.WriteString(_member.Assembly.Name);
            writer.WriteEndElement();

            if (_member.IsGeneric)
            {
                RenderGenericTypeParameters(_member.GetGenericTypes(), writer, comment);
            }

            RenderParameters(writer, comment);
            RenderExceptionBlock(_member, writer, comment);
            RenderPermissionBlock(_member, writer, comment);

            if (comment != XmlCodeComment.Empty)
            {
                RenderXmlBlock(writer, comment.Elements.Find(currentBlock => currentBlock is SummaryXmlCodeElement));
            }

            RenderSyntaxBlocks(_member, writer);
            RenderReturnsBlock(writer, comment);

            if (comment != XmlCodeComment.Empty)
            {
                RenderXmlBlock(writer, comment.Elements.Find(currentBlock => currentBlock is RemarksXmlCodeElement));
                RenderXmlBlock(writer, comment.Elements.Find(currentBlock => currentBlock is ExampleXmlCodeElement));
                RenderXmlBlock(writer, comment.Elements.Find(currentBlock => currentBlock is SeeAlsoXmlCodeElement));
            }

            RenderSeeAlsoBlock(_member, writer, comment);

            writer.WriteEndElement();
        }
Esempio n. 4
0
        public void DefaultCRefPath_ToString_ReturnsEmptyNamespace()
        {
            // it doesnt make sense to return an empty namespace string in these instances
            // I think it should return an empty string instead, but that is not a valid
            // crefpath - parhaps an error? Need to look in to this and change it as required.
            const string EXPECTED = "N:";

            CRefPath path = new CRefPath();

            Assert.AreEqual(EXPECTED, path.ToString());
        }
Esempio n. 5
0
 // checks if the entry is a ReflectedMember or a namespace and generates the cref attribute
 // fix: change this so it only outputs when I want it to!
 protected void WriteCref(Entry entry, System.Xml.XmlWriter writer)
 {
     // see DocumentMapper to see how entry.Item is populated
     if (entry.Item is ReflectedMember && !(entry.Item is AssemblyDef))
     { // assemblies cant be cref'd
         ReflectedMember member = entry.Item as ReflectedMember;
         CRefPath        path   = CRefPath.Create(member);
         writer.WriteAttributeString("cref", path.ToString());
     }
     else if (entry.Item is KeyValuePair <string, List <TypeDef> > )
     { // this is a namespace
         writer.WriteAttributeString("cref", "N:" + ((KeyValuePair <string, List <TypeDef> >)entry.Item).Key);
     }
 }
Esempio n. 6
0
        private static bool ResolveMember(string innerText, CRefPath path, AssemblyDef assembly, out CrefEntryKey key, out string displayName)
        {
            key         = new CrefEntryKey(assembly, path.ToString());
            displayName = innerText;

            // check if the member has been output by visual studio. If the cref is empty vs did not find it.
            // TODO: Return error text?
            if (path.PathType == CRefTypes.Error)
            {
                return(false);
            }

            TheBoxSoftware.Documentation.Entry relatedEntry = LiveDocumentorFile.Singleton.LiveDocument.Find(path);
            if (relatedEntry != null)
            {
                displayName = relatedEntry.Name;

                switch (path.PathType)
                {
                // these elements are named and the type of element will
                // not modify how it should be displayed
                case CRefTypes.Field:
                case CRefTypes.Property:
                case CRefTypes.Event:
                case CRefTypes.Namespace:
                    break;

                // these could be generic and so will need to modify to
                // a more appropriate display name
                case CRefTypes.Method:
                    MethodDef method = relatedEntry.Item as MethodDef;
                    if (method != null)
                    {
                        displayName = method.GetDisplayName(false);
                    }
                    break;

                case CRefTypes.Type:
                    TypeDef def = relatedEntry.Item as TypeDef;
                    if (def != null)
                    {
                        displayName = def.GetDisplayName(false);
                    }
                    break;
                }
            }

            return(relatedEntry != null);
        }
Esempio n. 7
0
        public void WhenTypeProvided_Creates_TypePath()
        {
            TypeDef type = new TypeDef();

            type.Name      = "MyName";
            type.Namespace = "Namespace";

            CRefPath result = new CRefPath(type);

            Assert.AreEqual(CRefTypes.Type, result.PathType);
            Assert.AreEqual(string.Empty, result.ElementName);
            Assert.AreEqual("MyName", result.TypeName);
            Assert.AreEqual("Namespace", result.Namespace);

            Assert.AreEqual("T:Namespace.MyName", result.ToString());
        }
Esempio n. 8
0
        public void WhenFieldProvided_Creates_FieldPath()
        {
            TypeDef container = new TypeDef();

            container.Name      = "Container";
            container.Namespace = "Namespace";
            FieldDef field = new FieldDef();

            field.Type = container;
            field.Name = "afield";

            CRefPath result = new CRefPath(field);

            Assert.AreEqual(CRefTypes.Field, result.PathType);
            Assert.AreEqual("afield", result.ElementName);
            Assert.AreEqual("Namespace", result.Namespace);
            Assert.AreEqual("Container", result.TypeName);

            Assert.AreEqual("F:Namespace.Container.afield", result.ToString());
        }
Esempio n. 9
0
        private void TestSearch()
        {
            CRefPath path   = CRefPath.Parse("M:theboxsoftware.api.livedocumenter.tableofcontents.getdocumentationfor(system.string)");
            Entry    member = this.document.Find(path);

            System.Console.Write(string.Format("[pass] found member {0} from path {1}\n", member.Name, path.ToString()));
        }
Esempio n. 10
0
        public void WhenCRefIsErrorType_ToString_ShouldReturnEmptyString()
        {
            CRefPath path = CRefPath.Parse("invalid string");

            Assert.AreEqual(string.Empty, path.ToString());
        }
        public override void Render(System.Xml.XmlWriter writer)
        {
            CRefPath       crefPath = new CRefPath(_member);
            XmlCodeComment comment  = _xmlComments.GetComment(crefPath);

            writer.WriteStartElement("member");
            writer.WriteAttributeString("id", AssociatedEntry.Key.ToString());
            writer.WriteAttributeString("subId", AssociatedEntry.SubKey);
            writer.WriteAttributeString("type", ReflectionHelper.GetType(_member));
            writer.WriteAttributeString("cref", crefPath.ToString());
            writer.WriteStartElement("name");
            writer.WriteAttributeString("safename", Exporter.CreateSafeName(_member.Name));
            writer.WriteString(_member.Name);
            writer.WriteEndElement();

            writer.WriteStartElement("namespace");
            Entry namespaceEntry = this.AssociatedEntry.FindNamespace(_member.Type.Namespace);

            writer.WriteAttributeString("id", namespaceEntry.Key.ToString());
            writer.WriteAttributeString("name", namespaceEntry.SubKey);
            writer.WriteAttributeString("cref", $"N:{_member.Type.Namespace}");
            writer.WriteString(_member.Type.Namespace);
            writer.WriteEndElement();
            writer.WriteStartElement("assembly");
            writer.WriteAttributeString("file", System.IO.Path.GetFileName(_member.Assembly.FileName));
            writer.WriteString(_member.Assembly.Name);
            writer.WriteEndElement();

            // find and output the summary
            if (comment != XmlCodeComment.Empty)
            {
                XmlCodeElement summary = comment.Elements.Find(currentBlock => currentBlock is SummaryXmlCodeElement);
                if (summary != null)
                {
                    Serialize(summary, writer);
                }
            }

            this.RenderPermissionBlock(_member, writer, comment);
            this.RenderSyntaxBlocks(_member, writer);

            // find and output the value
            if (comment != XmlCodeComment.Empty)
            {
                XmlCodeElement remarks = comment.Elements.Find(currentBlock => currentBlock is ValueXmlCodeElement);
                if (remarks != null)
                {
                    Serialize(remarks, writer);
                }
            }

            // find and output the summary
            if (comment != XmlCodeComment.Empty)
            {
                XmlCodeElement remarks = comment.Elements.Find(currentBlock => currentBlock is RemarksXmlCodeElement);
                if (remarks != null)
                {
                    Serialize(remarks, writer);
                }
            }

            // find and output the examples
            if (comment != XmlCodeComment.Empty)
            {
                XmlCodeElement remarks = comment.Elements.Find(currentBlock => currentBlock is ExampleXmlCodeElement);
                if (remarks != null)
                {
                    Serialize(remarks, writer);
                }
            }

            RenderSeeAlsoBlock(_member, writer, comment);

            writer.WriteEndElement();
        }