private void WriteTypeTarget(TypeTarget type, ReferenceLinkDisplayOptions options, bool showOuterType,
                                     XmlWriter writer)
        {
            // write namespace, if containers are requested
            if ((options & ReferenceLinkDisplayOptions.ShowContainer) > 0)
            {
                WriteNamespace(type.Namespace, ReferenceLinkDisplayOptions.Default, writer);
                WriteSeperator(writer);
            }

            // write outer type, if one exists
            if (showOuterType && (type.OuterType != null))
            {
                WriteSimpleType(type.OuterType, ReferenceLinkDisplayOptions.Default, writer);
                WriteSeperator(writer);
            }

            // write the type name
            writer.WriteString(type.Name);

            // write if template parameters, if they exist and we are requested
            if ((options & ReferenceLinkDisplayOptions.ShowTemplates) > 0)
            {
                WriteTemplateParameters(type.Templates, writer);
            }
        }
Beispiel #2
0
        private void WriteMemberTarget(MemberTarget target, ReferenceLinkDisplayOptions options, XmlWriter writer,
                                       IDictionary <IndexedTemplateTypeReference, TypeReference> dictionary)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if ((options & ReferenceLinkDisplayOptions.ShowContainer) > 0)
            {
                TypeReference type = target.Type;
                WriteType(type, options & ~ReferenceLinkDisplayOptions.ShowContainer, writer);
                if (target.TargetType == TargetType.Method)
                {
                    MethodTarget methodTarget = (MethodTarget)target;
                    if (methodTarget.conversionOperator)
                    {
                        writer.WriteString(" ");
                    }
                    else
                    {
                        WriteSeperator(writer);
                    }
                }
                else
                {
                    WriteSeperator(writer);
                }
            }

            switch (target.TargetType)
            {
            case TargetType.Method:
                // special logic for writing methods
                WriteMethod((MethodTarget)target, options, writer, dictionary);
                return;

            case TargetType.Property:
                // special logic for writing properties
                WriteProperty((PropertyTarget)target, options, writer);
                return;

            case TargetType.Constructor:
                // special logic for writing constructors
                WriteConstructor((ConstructorTarget)target, options, writer);
                return;

            case TargetType.Event:
                // special logic for writing events
                WriteEvent((EventTarget)target, options, writer);
                return;
            }

            // by default, just write name
            writer.WriteString(target.Name);
        }
        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);
            }
        }
        public void WriteMember(MemberReference member, ReferenceLinkDisplayOptions options, XmlWriter writer)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            switch (member.ReferenceType)
            {
            case ReferenceType.SimpleMember:
                WriteSimpleMember((SimpleMemberReference)member, options, writer);
                return;

            case ReferenceType.SpecializedMember:
                WriteSpecializedMember((SpecializedMemberReference)member, options, writer);
                return;

            case ReferenceType.SpecializedMemberWithParameters:
                WriteSpecializedMemberWithParameters((SpecializedMemberWithParametersReference)member,
                                                     options, writer);
                return;
            }

            throw new InvalidOperationException();
        }
        private void WriteMethod(MethodTarget target, ReferenceLinkDisplayOptions options, XmlWriter writer,
                                 IDictionary <IndexedTemplateTypeReference, TypeReference> dictionary)
        {
            WriteProcedureName(target, options, writer);

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

            if ((options & ReferenceLinkDisplayOptions.ShowParameters) > 0)
            {
                IList <Parameter> parameters = target.Parameters;

                if (target.ConversionOperator)
                {
                    TypeReference returns = target.returnType;
                    WriteConversionOperatorParameters(parameters, returns, writer, dictionary);
                }
                else
                {
                    WriteMethodParameters(parameters, writer, dictionary);
                }
            }
        }
        private void WriteSpecializedMemberWithParameters(SpecializedMemberWithParametersReference ugly,
                                                          ReferenceLinkDisplayOptions options, XmlWriter writer)
        {
            if ((options & ReferenceLinkDisplayOptions.ShowContainer) > 0)
            {
                WriteSpecializedType(ugly.SpecializedType, options & ~ReferenceLinkDisplayOptions.ShowContainer, writer);
                WriteSeperator(writer);
            }

            writer.WriteString(ugly.MemberName);

            if ((options & ReferenceLinkDisplayOptions.ShowParameters) > 0)
            {
                writer.WriteString("(");

                IList <TypeReference> parameterTypes = ugly.ParameterTypes;
                for (int i = 0; i < parameterTypes.Count; i++)
                {
                    if (i > 0)
                    {
                        writer.WriteString(", ");
                    }

                    WriteType(parameterTypes[i], ReferenceLinkDisplayOptions.Default, writer);
                }

                writer.WriteString(")");
            }
        }
        private void WriteConstructor(ConstructorTarget constructor, ReferenceLinkDisplayOptions options, XmlWriter writer)
        {
            WriteType(constructor.Type, options & ~ReferenceLinkDisplayOptions.ShowContainer, writer);

            if ((options & ReferenceLinkDisplayOptions.ShowParameters) > 0)
            {
                IList <Parameter> parameters = constructor.Parameters;
                WriteMethodParameters(parameters, writer);
            }
        }
Beispiel #8
0
        private void WriteSpecialization(Specialization specialization,
                                         ReferenceLinkDisplayOptions options, XmlWriter writer)
        {
            // write the type itself (without outer types, because those will be written be other calls to this routine)
            WriteSimpleType(specialization.TemplateType, (options & ~ReferenceLinkDisplayOptions.ShowTemplates),
                            false, writer);

            // then write the template arguments
            WriteTemplateArguments(specialization.arguments, writer);
        }
        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();
        }
        public void WriteNamespaceTarget(NamespaceTarget space, ReferenceLinkDisplayOptions options, XmlWriter writer)
        {
            if (space == null)
            {
                throw new ArgumentNullException("target");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            writer.WriteString(space.Name);
        }
        public void WriteTypeTarget(TypeTarget type, ReferenceLinkDisplayOptions options, XmlWriter writer)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            WriteTypeTarget(type, options, true, writer);
        }
        private void WriteTemplateType(TemplateTypeReference template, ReferenceLinkDisplayOptions options,
                                       XmlWriter writer, IDictionary <IndexedTemplateTypeReference, TypeReference> dictionary)
        {
            switch (template.ReferenceType)
            {
            case ReferenceType.NamedTemplate:
                // if we have the name, just write it
                NamedTemplateTypeReference namedTemplate = (NamedTemplateTypeReference)template;
                writer.WriteString(namedTemplate.Name);
                return;

            case ReferenceType.IndexedTemplate:
                IndexedTemplateTypeReference indexedTemplate = (IndexedTemplateTypeReference)template;
                if ((dictionary != null) && (dictionary.ContainsKey(indexedTemplate)))
                {
                    WriteType(dictionary[indexedTemplate], options, writer);
                }
                else
                {
                    writer.WriteString(GetTemplateName(indexedTemplate.TemplateId, indexedTemplate.Index));
                }
                return;

            case ReferenceType.TypeTemplate:
                TypeTemplateTypeReference typeTemplate = (TypeTemplateTypeReference)template;

                TypeReference value = null;
                if (dictionary != null)
                {
                    IndexedTemplateTypeReference key = new IndexedTemplateTypeReference(
                        typeTemplate.TemplateType.Id, typeTemplate.Position);
                    if (dictionary.ContainsKey(key))
                    {
                        value = dictionary[key];
                    }
                }

                if (value == null)
                {
                    writer.WriteString(GetTypeTemplateName(typeTemplate.TemplateType,
                                                           typeTemplate.Position));
                }
                else
                {
                    WriteType(value, options, writer);
                }
                return;
            }

            throw new InvalidOperationException();
        }
        private void WriteReferenceType(ReferenceTypeReference reference, ReferenceLinkDisplayOptions options,
                                        XmlWriter writer, IDictionary <IndexedTemplateTypeReference, TypeReference> dictionary)
        {
            WriteType(reference.ReferedToType, options, writer, dictionary);

            writer.WriteStartElement("span");
            writer.WriteAttributeString("class", "languageSpecificText");
            // add % in C++
            writer.WriteStartElement("span");
            writer.WriteAttributeString("class", "cpp");
            writer.WriteString("%");
            writer.WriteEndElement();
            writer.WriteEndElement();
        }
        private void WriteSimpleType(SimpleTypeReference simple, ReferenceLinkDisplayOptions options,
                                     bool showOuterType, XmlWriter writer)
        {
            TypeTarget type = simple.Resolve(_targets) as TypeTarget;

            if (type != null)
            {
                WriteTypeTarget(type, options, showOuterType, writer);
            }
            else
            {
                ReferenceTextUtilities.WriteSimpleTypeReference(simple, options, writer);
            }
        }
        private void WriteSpecializedMember(SpecializedMemberReference member, ReferenceLinkDisplayOptions options,
                                            XmlWriter writer)
        {
            if ((options & ReferenceLinkDisplayOptions.ShowContainer) > 0)
            {
                WriteType(member.SpecializedType, options & ~ReferenceLinkDisplayOptions.ShowContainer, writer);
                WriteSeperator(writer);
            }

            IDictionary <IndexedTemplateTypeReference, TypeReference> dictionary
                = member.SpecializedType.GetSpecializationDictionary();

            WriteSimpleMember(member.TemplateMember, options & ~ReferenceLinkDisplayOptions.ShowContainer,
                              writer, dictionary);
        }
        private void WriteSimpleMember(SimpleMemberReference member, ReferenceLinkDisplayOptions options,
                                       XmlWriter writer, IDictionary <IndexedTemplateTypeReference, TypeReference> dictionary)
        {
            MemberTarget target = member.Resolve(_targets) as MemberTarget;

            if (target != null)
            {
                WriteMemberTarget(target, options, writer, dictionary);
            }
            else
            {
                ReferenceTextUtilities.WriteSimpleMemberReference(member, options, writer, this);
                //throw new InvalidOperationException(String.Format("Unknown member target '{0}'", member.Id));
            }
        }
        private void WriteType(TypeReference type, ReferenceLinkDisplayOptions options, XmlWriter writer,
                               IDictionary <IndexedTemplateTypeReference, TypeReference> dictionary)
        {
            if (type == null)
            {
                return;
            }

            //if (type == null)
            //    throw new ArgumentNullException("type");
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            switch (type.ReferenceType)
            {
            case ReferenceType.SimpleType:
                WriteSimpleType((SimpleTypeReference)type, options, writer);
                return;

            case ReferenceType.SpecializedType:
                WriteSpecializedType((SpecializedTypeReference)type, options, writer);
                return;

            case ReferenceType.ArrayType:
                WriteArrayType((ArrayTypeReference)type, options, writer, dictionary);
                return;

            case ReferenceType.ReferenceType:
                WriteReferenceType((ReferenceTypeReference)type, options, writer, dictionary);
                return;

            case ReferenceType.PointerType:
                WritePointerType((PointerTypeReference)type, options, writer, dictionary);
                return;

            case ReferenceType.TypeTemplate:
            case ReferenceType.IndexedTemplate:
            case ReferenceType.NamedTemplate:
            case ReferenceType.MethodTemplate:
                WriteTemplateType((TemplateTypeReference)type, options, writer, dictionary);
                return;
            }

            throw new InvalidOperationException("Unknown type reference type");
        }
        private void WriteSpecializedType(SpecializedTypeReference special,
                                          ReferenceLinkDisplayOptions options, XmlWriter writer)
        {
            IList <Specialization> specializations = special.Specializations;

            for (int i = 0; i < specializations.Count; i++)
            {
                if (i == 0)
                {
                    WriteSpecialization(specializations[0], options, writer);
                }
                else
                {
                    WriteSeperator(writer);
                    WriteSpecialization(specializations[i], options & ~ReferenceLinkDisplayOptions.ShowContainer, writer);
                }
            }
        }
        internal static void WriteSimpleMemberReference(SimpleMemberReference member,
                                                        ReferenceLinkDisplayOptions options, XmlWriter writer, ReferenceLinkTextResolver resolver)
        {
            string cer = member.Id;

            string typeCer, memberName, arguments;

            DecomposeMemberIdentifier(cer, out typeCer, out memberName, out arguments);

            if ((options & ReferenceLinkDisplayOptions.ShowContainer) > 0)
            {
                SimpleTypeReference type = CreateSimpleTypeReference(typeCer);
                WriteSimpleTypeReference(type, options & ~ReferenceLinkDisplayOptions.ShowContainer, writer);
            }

            // change this so that we deal with EII names correctly, too
            writer.WriteString(memberName);

            if ((options & ReferenceLinkDisplayOptions.ShowParameters) > 0)
            {
                if (String.IsNullOrEmpty(arguments))
                {
                    Parameter[] parameters = new Parameter[0];
                    resolver.WriteMethodParameters(parameters, writer);
                }
                else
                {
                    IList <string> parameterTypeCers = SeparateTypes(arguments);
                    Parameter[]    parameters        = new Parameter[parameterTypeCers.Count];
                    for (int i = 0; i < parameterTypeCers.Count; i++)
                    {
                        TypeReference parameterType = CreateTypeReference(parameterTypeCers[i]);
                        if (parameterType == null)
                        {
                            parameterType = new NamedTemplateTypeReference("UAT");
                        }
                        parameters[i] = new Parameter(String.Empty, parameterType);
                    }

                    resolver.WriteMethodParameters(parameters, writer);
                }
            }
        }
        internal static void WriteSimpleTypeReference(SimpleTypeReference type,
                                                      ReferenceLinkDisplayOptions options, XmlWriter writer)
        {
            // this logic won't correctly deal with nested types, but type cer strings simply don't include that
            // information, so this is out best guess under the assumption of a non-nested type

            string cer = type.Id;

            // get the name
            string name;
            int    lastDotPosition = cer.LastIndexOf('.');

            if (lastDotPosition > 0)
            {
                // usually, the name will start after the last dot
                name = cer.Substring(lastDotPosition + 1);
            }
            else
            {
                // but if there is no dot, this is a type in the default namespace and the name is everything after the colon
                name = cer.Substring(2);
            }

            // remove any generic tics from the name
            int tickPosition = name.IndexOf('`');

            if (tickPosition > 0)
            {
                name = name.Substring(0, tickPosition);
            }

            if ((options & ReferenceLinkDisplayOptions.ShowContainer) > 0)
            {
                // work out namespace
            }

            writer.WriteString(name);

            if ((options & ReferenceLinkDisplayOptions.ShowTemplates) > 0)
            {
                // work out templates
            }
        }
        private void WriteProcedureName(ProcedureTarget target, ReferenceLinkDisplayOptions options, XmlWriter writer)
        {
            MemberReference implements = target.ExplicitlyImplements;

            if (implements == null)
            {
                if (target.conversionOperator)
                {
                    WriteConversionOperator(target, writer);
                }
                else
                {
                    writer.WriteString(target.Name);
                }
            }
            else
            {
                WriteMember(implements, ReferenceLinkDisplayOptions.ShowContainer, writer);
            }
        }
        public void WriteNamespace(NamespaceReference spaceReference, ReferenceLinkDisplayOptions options,
                                   XmlWriter writer)
        {
            if (spaceReference == null)
            {
                throw new ArgumentNullException("spaceReference");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            NamespaceTarget spaceTarget = spaceReference.Resolve(_targets) as NamespaceTarget;

            if (spaceTarget != null)
            {
                WriteNamespaceTarget(spaceTarget, options, writer);
            }
            else
            {
                ReferenceTextUtilities.WriteNamespaceReference(spaceReference, options, writer);
            }
        }
        public void WriteTarget(Target target, ReferenceLinkDisplayOptions options, XmlWriter writer)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            switch (target.TargetType)
            {
            case TargetType.Namespace:
                WriteNamespaceTarget((NamespaceTarget)target, options, writer);
                return;

            // For the TypeTarget...
            case TargetType.Type:
            case TargetType.Enumeration:
                WriteTypeTarget((TypeTarget)target, options, writer);
                return;

            // For the MemberTarget...
            case TargetType.Member:
            case TargetType.Constructor:
            case TargetType.Procedure:
            case TargetType.Event:
            case TargetType.Property:
            case TargetType.Method:
                WriteMemberTarget((MemberTarget)target, options, writer);
                return;
            }

            throw new InvalidOperationException();
        }
        private void WriteArrayType(ArrayTypeReference reference, ReferenceLinkDisplayOptions options,
                                    XmlWriter writer, IDictionary <IndexedTemplateTypeReference, TypeReference> dictionary)
        {
            writer.WriteStartElement("span");
            writer.WriteAttributeString("class", "languageSpecificText");
            // C++ array notation (left)
            writer.WriteStartElement("span");
            writer.WriteAttributeString("class", "cpp");
            writer.WriteString("array<");
            writer.WriteEndElement();
            writer.WriteEndElement(); // end of <span class="languageSpecificText"> element

            // the underlying type
            WriteType(reference.ElementType, options, writer, dictionary);

            // C++ array notation (right)
            writer.WriteStartElement("span");
            writer.WriteAttributeString("class", "languageSpecificText");
            writer.WriteStartElement("span");
            writer.WriteAttributeString("class", "cpp");
            if (reference.Rank > 1)
            {
                writer.WriteString("," + reference.Rank.ToString());
            }
            writer.WriteString(">");
            writer.WriteEndElement();

            // C# array notation
            writer.WriteStartElement("span");
            writer.WriteAttributeString("class", "cs");
            writer.WriteString("[");
            for (int i = 1; i < reference.Rank; i++)
            {
                writer.WriteString(",");
            }
            writer.WriteString("]");
            writer.WriteEndElement();

            // VB array notation
            writer.WriteStartElement("span");
            writer.WriteAttributeString("class", "vb");
            writer.WriteString("(");
            for (int i = 1; i < reference.Rank; i++)
            {
                writer.WriteString(",");
            }
            writer.WriteString(")");
            writer.WriteEndElement();

            // neutral array notation
            writer.WriteStartElement("span");
            writer.WriteAttributeString("class", "nu");
            writer.WriteString("[");
            for (int i = 1; i < reference.Rank; i++)
            {
                writer.WriteString(",");
            }
            writer.WriteString("]");
            writer.WriteEndElement();

            // F# array notation
            writer.WriteStartElement("span");
            writer.WriteAttributeString("class", "fs");
            writer.WriteString("[");
            for (int i = 1; i < reference.Rank; i++)
            {
                writer.WriteString(",");
            }
            writer.WriteString("]");
            writer.WriteEndElement();

            writer.WriteEndElement(); // end of <span class="languageSpecificText"> element
        }
        // Writing link text for unresolved simple references

        internal static void WriteNamespaceReference(NamespaceReference space, ReferenceLinkDisplayOptions options,
                                                     XmlWriter writer)
        {
            writer.WriteString(space.Id.Substring(2));
        }
 public void WriteSimpleType(SimpleTypeReference simple, ReferenceLinkDisplayOptions options, XmlWriter writer)
 {
     WriteSimpleType(simple, options, true, writer);
 }
 private void WriteSimpleMember(SimpleMemberReference member, ReferenceLinkDisplayOptions options, XmlWriter writer)
 {
     WriteSimpleMember(member, options, writer, null);
 }
 private void WriteTemplateType(TemplateTypeReference template, ReferenceLinkDisplayOptions options,
                                XmlWriter writer)
 {
     WriteTemplateType(template, options, writer, null);
 }
 private ReferenceLinkInfo()
 {
     _options = ReferenceLinkDisplayOptions.Default;
 }
 private void WritePointerType(PointerTypeReference pointer, ReferenceLinkDisplayOptions options,
                               XmlWriter writer, IDictionary <IndexedTemplateTypeReference, TypeReference> dictionary)
 {
     WriteType(pointer.PointedToType, options, writer, dictionary);
     writer.WriteString("*");
 }