예제 #1
0
        /// <summary>
        /// Executes name processing of the current method 'M:' or type 'T:' &lt;member&gt; element.
        /// </summary>
        /// <param name="writer">The current StringWriter to use.</param>
        /// <param name="root">The current root element to process.</param>
        /// <param name="context">The current processing context.</param>
        /// <returns>The updated processing context.</returns>
        public override Dictionary <XName, string> Process(StringWriter writer, XElement root, Dictionary <XName, string> context)
        {
            Args.IsNotNull(() => writer, () => root, () => context);

            var  memberName = root.Attribute(XName.Get("name")).Value;
            char memberType = memberName[0];

            if (memberType == 'M')
            {
                memberName = MethodTypeProcessor.RearrangeTypeParametersInContext(root, memberName, context, false);
                memberName = MethodTypeProcessor.RearrangeParametersInContext(root, memberName, context);
            }

            context["memberName"] = memberName;

            if (memberType == 'T')
            {
                var typeNameStartIndex = 3 + context["assembly"].Length;
                var scrubbedName       = MethodTypeProcessor.ReplaceForTypeParameters(root, memberName, false, context);
                var shortMemberName    = scrubbedName.Substring(typeNameStartIndex);
                writer.WriteLine("\n## {0}\n", shortMemberName);
                context["typeName"] = shortMemberName;
            }

            context["memberType"] = memberType.ToString();

            context["lastNode"] = memberName;

            return(base.Process(writer, root, context));
        }
예제 #2
0
        private static string ReplaceForTypeParameters(XElement methodMember, string memberName, bool methodType, Dictionary <XName, string> context)
        {
            string methodPrototype = memberName;
            var    matches         = Regex.Matches(methodPrototype, "\\`(\\d)"); //Matches: '1 and 1 //M:GraphExec.BaseEventAggregator.GetEventType`1

            // Match 1 = Type Parameter Count ('1)

            if (matches.Count == 0)
            {
                return(methodPrototype);
            }

            var typeParamCount = Convert.ToInt32(matches[0].Groups[1].Value);

            List <XElement> paramElems = new List <XElement>(methodMember.Elements("typeparam"));

            if (typeParamCount != paramElems.Count)
            {
                System.Diagnostics.Debug.WriteLine("Type Parameters and TypeParamList not equal for replacing generic types' type parameters.");
                // the parameter count do not match, we can't do the rearrangement.
                return(methodPrototype);
            }

            string newParamString = "";

            for (int i = 0; i < paramElems.Count; i++)
            {
                XElement paramElem = paramElems[i];
                string   paramType = paramElem.Attribute(XName.Get("name")).Value;
                if (newParamString != "")
                {
                    newParamString += ", ";
                }
                newParamString    += paramType;
                context[paramType] = paramType;
            }

            var paramMatches = Regex.Matches(methodPrototype, "\\{``\\d}");

            if (paramMatches.Count > 0) // {``0} and {``1} and {``2``3}
            {
                methodPrototype = MethodTypeProcessor.RearrangeTypeParametersInContext(methodMember, methodPrototype, context, true);
            }

            if (methodType)
            {
                string newMethodPrototype = Regex.Replace(methodPrototype,
                                                          "\\``\\d",
                                                          "&lt;" + newParamString + "&gt;");

                return(newMethodPrototype);
            }
            else
            {
                string newMethodPrototype = Regex.Replace(methodPrototype,
                                                          "\\`\\d",
                                                          "&lt;" + newParamString + "&gt;");

                return(newMethodPrototype);
            }
        }