Exemplo n.º 1
0
        public string HumanNameFromDescriptor(string descriptor, string parentTypeOrNamespace = null)
        {
            var descriptorElements = descriptor.Split(':');

            if (descriptorElements.Length != 2 || descriptorElements[0].Length != 1)
            {
                throw new InvalidOperationException(String.Format("Invalid name descriptor: '{0}'", descriptor));
            }

            var memberType = MemberDoc.TypeFromDescriptor(descriptorElements[0][0]);
            var fullName   = descriptorElements[1];

            // Cut away any method signatures
            var fullNameNoSig = fullName.Split(new char[] { '(' }, 2)[0];


            if (String.IsNullOrEmpty(parentTypeOrNamespace))
            {
                return(fullName);
            }

            var commonPrefix = "";
            var dotIndex     = fullNameNoSig.LastIndexOf('.');

            if (dotIndex >= 0)
            {
                var possiblePrefix = fullNameNoSig.Substring(0, dotIndex);
                commonPrefix = CommonNamespacePrefix(possiblePrefix, parentTypeOrNamespace);
            }

            //if(memberType == MemberType.Type || memberType == MemberType.Namespace)
            return(fullNameNoSig.Substring(commonPrefix.Length + 1));

            /*else
             * {
             *  var declaringTypeName = fullNameNoSig.Substring(0, fullNameNoSig.LastIndexOf('.'));
             *  var declaringType = AssemblyInfo.GetType(declaringTypeName);
             *  if(declaringType == null || declaringType.FullName != parentTypeOrNamespace)
             *      return fullNameNoSig.Substring(commonPrefix.Length + 1);
             *  else
             *  {
             *      // So the given descriptor
             *      var memberName = fullName.Substring(commonPrefix.Length + 1);
             *
             *
             *      // For everything except methods, just return the member name
             *      if (memberType != MemberType.Method)
             *          return memberName;
             *
             *      // Try to find the exact matching method so we can print the correct signature
             *      var possibleMatches = declaringType.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
             *      foreach(var match in possibleMatches)
             *      {
             *          var memberId = FullNameFromMember(match);
             *          if (memberId == fullName)
             *              return match.Name + MakeSignature(match, true);
             *      }
             *
             *      return memberName;
             *  }
             * }
             */
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parsed a single member node from the xml documentation and returns the corresponding MemberDoc object.
        /// </summary>
        public MemberDoc ParseMember(XElement member)
        {
            var memberInfo = new MemberDoc();

            string nameDescriptor = member.Attribute("name").Value;
            var descriptorElements = nameDescriptor.Split(':');

            if (descriptorElements.Length != 2)
                throw new InvalidOperationException(String.Format(
                        "Invalid name descriptor in line {0}: '{1}'",
                        ((IXmlLineInfo)member).LineNumber,
                        nameDescriptor
                        ));

            memberInfo.Type = MemberDoc.TypeFromDescriptor(descriptorElements[0][0]);

            memberInfo.FullName = descriptorElements[1];
            memberInfo.LocalName = memberInfo.FullName;

            var xImportance = member.Element("importance");
            if (xImportance != null)
            {
                int importance = 0;
                if(int.TryParse(xImportance.Value, out importance))
                    memberInfo.Importance = importance;
            }

            var xSummary = member.Element("summary");
            if (xSummary != null)
                memberInfo.Summary = ParseDocText(xSummary, memberInfo.FullName);

            var xRemarks = member.Element("remarks");
            if (xRemarks != null)
                memberInfo.Remarks = ParseDocText(xRemarks, memberInfo.FullName);

            var xReturns = member.Element("returns");
            if (xReturns != null)
                memberInfo.Returns = ParseDocText(xReturns, memberInfo.FullName);

            var xExample = member.Element("example");
            if (xExample != null)
                memberInfo.Example = ParseDocText(xExample, memberInfo.FullName);

            var xParams = member.Elements("param");
            foreach(var param in xParams)
            {
                var name = param.Attribute("name").Value;
                memberInfo.ParameterDescriptionsByName[name] = ParseDocText(param, memberInfo.FullName);
            }

            return memberInfo;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parsed a single member node from the xml documentation and returns the corresponding MemberDoc object.
        /// </summary>
        public MemberDoc ParseMember(XElement member)
        {
            var memberInfo = new MemberDoc();

            string nameDescriptor     = member.Attribute("name").Value;
            var    descriptorElements = nameDescriptor.Split(':');

            if (descriptorElements.Length != 2)
            {
                throw new InvalidOperationException(String.Format(
                                                        "Invalid name descriptor in line {0}: '{1}'",
                                                        ((IXmlLineInfo)member).LineNumber,
                                                        nameDescriptor
                                                        ));
            }

            memberInfo.Type = MemberDoc.TypeFromDescriptor(descriptorElements[0][0]);

            memberInfo.FullName  = descriptorElements[1];
            memberInfo.LocalName = memberInfo.FullName;

            var xImportance = member.Element("importance");

            if (xImportance != null)
            {
                int importance = 0;
                if (int.TryParse(xImportance.Value, out importance))
                {
                    memberInfo.Importance = importance;
                }
            }


            var xSummary = member.Element("summary");

            if (xSummary != null)
            {
                memberInfo.Summary = ParseDocText(xSummary, memberInfo.FullName);
            }

            var xRemarks = member.Element("remarks");

            if (xRemarks != null)
            {
                memberInfo.Remarks = ParseDocText(xRemarks, memberInfo.FullName);
            }

            var xReturns = member.Element("returns");

            if (xReturns != null)
            {
                memberInfo.Returns = ParseDocText(xReturns, memberInfo.FullName);
            }

            var xExample = member.Element("example");

            if (xExample != null)
            {
                memberInfo.Example = ParseDocText(xExample, memberInfo.FullName);
            }

            var xParams = member.Elements("param");

            foreach (var param in xParams)
            {
                var name = param.Attribute("name").Value;
                memberInfo.ParameterDescriptionsByName[name] = ParseDocText(param, memberInfo.FullName);
            }

            return(memberInfo);
        }