public void WriteExtensionMethod(ExtensionMethodReference extMethod, ReferenceLinkDisplayOptions options,
                                         XmlWriter writer)
        {
            if (extMethod == null)
            {
                throw new ArgumentNullException("extMethod");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            // write the unqualified method name
            writer.WriteString(extMethod.Name);

            // if this is a generic method, write any template params or args
            if (extMethod.TemplateArgs != null && extMethod.TemplateArgs.Count > 0)
            {
                WriteTemplateArguments(extMethod.TemplateArgs, writer);
            }

            // write parameters
            if ((options & ReferenceLinkDisplayOptions.ShowParameters) > 0)
            {
                IList <Parameter> parameters = extMethod.Parameters;
                WriteMethodParameters(extMethod.Parameters, writer);
            }
        }
        /// <summary>
        /// Create an object to store the information to generate the display string for an extension method
        /// </summary>
        /// <param name="node">xml node containing the extension method data</param>
        /// <returns></returns>
        public static ExtensionMethodReference CreateExtensionMethodReference(XPathNavigator node)
        {
            string               methodName = (string)node.Evaluate(apiNameExpression);
            IList <Parameter>    parameters = CreateParameterList(node);
            List <TypeReference> templateArgumentReferences = null;
            // List<TemplateName> templateNames = new List<TemplateName>();

            // this selects templates/template or templates/type, because extension methods can have a mix of generic and specialization
            // get the short name of each template param or template arg
            XPathNodeIterator templateNodes = node.Select(methodTemplateArgsExpression);

            if (templateNodes != null && templateNodes.Count > 0)
            {
                templateArgumentReferences = new List <TypeReference>(templateNodes.Count);
                int i = 0;
                foreach (XPathNavigator templateNode in templateNodes)
                {
                    templateArgumentReferences.Add(CreateTypeReference(templateNode));
                    i++;
                }
            }

            ExtensionMethodReference extMethod = new ExtensionMethodReference(methodName,
                                                                              parameters, templateArgumentReferences);

            return(extMethod);
        }
        public void WriteReference(Reference reference, ReferenceLinkDisplayOptions options, XmlWriter writer)
        {
            if (reference == null)
            {
                throw new ArgumentNullException("reference");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            NamespaceReference space = reference as NamespaceReference;

            if (space != null)
            {
                WriteNamespace(space, options, writer);
                return;
            }

            TypeReference type = reference as TypeReference;

            if (type != null)
            {
                WriteType(type, options, writer);
                return;
            }

            MemberReference member = reference as MemberReference;

            if (member != null)
            {
                WriteMember(member, options, writer);
                return;
            }

            ExtensionMethodReference extMethod = reference as ExtensionMethodReference;

            if (extMethod != null)
            {
                WriteExtensionMethod(extMethod, options, writer);
                return;
            }

            InvalidReference invalid = reference as InvalidReference;

            if (invalid != null)
            {
                WriteInvalid(invalid, options, writer);
                return;
            }

            throw new InvalidOperationException();
        }
Example #4
0
        public static Reference ReadReference(XmlReader reader)
        {
            if (reader == null || reader.NodeType != XmlNodeType.Element)
            {
                return(null);
            }

            switch (reader.Name)
            {
            case "InvalidReference":
                InvalidReference invalidReference = new InvalidReference();
                invalidReference.ReadXml(reader);
                return(invalidReference);

            case "NamespaceReference":
                NamespaceReference namespaceReference = new NamespaceReference();
                namespaceReference.ReadXml(reader);
                return(namespaceReference);

            case "ExtensionMethodReference":
                ExtensionMethodReference extensionMethodReference = new ExtensionMethodReference();
                extensionMethodReference.ReadXml(reader);
                return(extensionMethodReference);

            // For the MemberReference(s)...
            case "SimpleMemberReference":
                SimpleMemberReference simpleMemberReference = new SimpleMemberReference();
                simpleMemberReference.ReadXml(reader);
                return(simpleMemberReference);

            case "SpecializedMemberReference":
                SpecializedMemberReference specializedMemberReference = new SpecializedMemberReference();
                specializedMemberReference.ReadXml(reader);
                return(specializedMemberReference);

            case "SpecializedMemberWithParametersReference":
                SpecializedMemberWithParametersReference specializedMemberWithParametersReference
                    = new SpecializedMemberWithParametersReference();
                specializedMemberWithParametersReference.ReadXml(reader);
                return(specializedMemberWithParametersReference);

            // For the TypeReference(s)...
            case "SimpleTypeReference":
                SimpleTypeReference simpleTypeReference = new SimpleTypeReference();
                simpleTypeReference.ReadXml(reader);
                return(simpleTypeReference);

            case "SpecializedTypeReference":
                SpecializedTypeReference specializedTypeReference = new SpecializedTypeReference();
                specializedTypeReference.ReadXml(reader);
                return(specializedTypeReference);

            case "ArrayTypeReference":
                ArrayTypeReference arrayTypeReference = new ArrayTypeReference();
                arrayTypeReference.ReadXml(reader);
                return(arrayTypeReference);

            case "ReferenceTypeReference":
                ReferenceTypeReference referenceTypeReference = new ReferenceTypeReference();
                referenceTypeReference.ReadXml(reader);
                return(referenceTypeReference);

            case "PointerTypeReference":
                PointerTypeReference pointerTypeReference = new PointerTypeReference();
                pointerTypeReference.ReadXml(reader);
                return(pointerTypeReference);

            // For the TemplateTypeReference(s)...
            case "IndexedTemplateTypeReference":
                IndexedTemplateTypeReference indexedTemplateTypeReference =
                    new IndexedTemplateTypeReference();
                indexedTemplateTypeReference.ReadXml(reader);
                return(indexedTemplateTypeReference);

            case "NamedTemplateTypeReference":
                NamedTemplateTypeReference namedTemplateTypeReference = new NamedTemplateTypeReference();
                namedTemplateTypeReference.ReadXml(reader);
                return(namedTemplateTypeReference);

            case "TypeTemplateTypeReference":
                TypeTemplateTypeReference typeTemplateTypeReference = new TypeTemplateTypeReference();
                typeTemplateTypeReference.ReadXml(reader);
                return(typeTemplateTypeReference);

            case "MethodTemplateTypeReference":
                MethodTemplateTypeReference methodTemplateTypeReference = new MethodTemplateTypeReference();
                methodTemplateTypeReference.ReadXml(reader);
                return(methodTemplateTypeReference);
            }

            return(null);
        }