コード例 #1
0
        private static SpecializedTypeReference CreateSpecializedTypeReference(string api)
        {
            List <Specialization> specializations = new List <Specialization>();

            string text = String.Copy(api);

            // At the moment we are only handling one specialization; need to iterate
            int            specializationStart = text.IndexOf('{');
            int            specializationEnd   = FindMatchingEndBracket(text, specializationStart);
            string         list     = text.Substring(specializationStart + 1, specializationEnd - specializationStart - 1);
            IList <string> types    = SeparateTypes(list);
            string         template = text.Substring(0, specializationStart) + String.Format(CultureInfo.InvariantCulture,
                                                                                             "`{0}", types.Count);

            SimpleTypeReference templateReference = CreateSimpleTypeReference(template);

            TypeReference[] argumentReferences = new TypeReference[types.Count];

            for (int i = 0; i < types.Count; i++)
            {
                argumentReferences[i] = CreateTypeReference(types[i]);
            }

            Specialization specialization = new Specialization(templateReference, argumentReferences);

            specializations.Add(specialization);

            // end iteration

            return(new SpecializedTypeReference(specializations));
        }
コード例 #2
0
        /// <summary>
        /// Set the generic context
        /// </summary>
        /// <param name="codeEntityReference">The member ID for which to set the context</param>
        public static void SetGenericContext(string codeEntityReference)
        {
            // Reset the context
            genericTypeContext = null;

            // Get the new context
            Reference context = CreateReference(codeEntityReference);

            if (context == null)
            {
                return;
            }

            // If it is a type context, set it to be the type context
            if (context is SimpleTypeReference typeContext)
            {
                genericTypeContext = typeContext;
                return;
            }

            // If it is a member context, set it to be the member context and use it to obtain a type context, too
            if (context is SimpleMemberReference memberContext)
            {
                DecomposeMemberIdentifier(memberContext.Id, out string typeId, out _, out _);
                genericTypeContext = CreateSimpleTypeReference(typeId);
                return;
            }
        }
コード例 #3
0
ファイル: LinkTextResolver.cs プロジェクト: Tyler-Zhou/SHFB
        /// <summary>
        /// Write out a simple type reference
        /// </summary>
        /// <param name="simple">The simple type reference information</param>
        /// <param name="options">The link display options</param>
        /// <param name="writer">The write to which the information is written</param>
        public void WriteSimpleType(SimpleTypeReference simple, DisplayOptions options, XmlWriter writer)
        {
            if (simple == null)
            {
                throw new ArgumentNullException(nameof(simple));
            }

            WriteSimpleType(simple, options, true, writer);
        }
コード例 #4
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="templateType">The template type</param>
        /// <param name="position">The position</param>
        public TypeTemplateTypeReference(SimpleTypeReference templateType, int position)
        {
            if (position < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(position));
            }

            this.TemplateType = templateType ?? throw new ArgumentNullException(nameof(templateType));
            this.Position     = position;
        }
コード例 #5
0
ファイル: LinkTextResolver.cs プロジェクト: Tyler-Zhou/SHFB
 private void WriteSimpleType(SimpleTypeReference simple, DisplayOptions options, bool showOuterType, XmlWriter writer)
 {
     if (targets[simple.Id] is TypeTarget type)
     {
         WriteTypeTarget(type, options, showOuterType, writer);
     }
     else
     {
         TextReferenceUtilities.WriteSimpleTypeReference(simple, options, writer);
     }
 }
コード例 #6
0
        internal static void WriteSimpleMemberReference(SimpleMemberReference member, DisplayOptions options, XmlWriter writer, LinkTextResolver resolver)
        {
            string cer = member.Id;

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

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

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

            if ((options & DisplayOptions.ShowParameters) > 0)
            {
                if (String.IsNullOrEmpty(arguments))
                {
                    Parameter[] parameters = Array.Empty <Parameter>();
                    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);
                }
            }
        }
コード例 #7
0
        internal static void WriteSimpleTypeReference(SimpleTypeReference type, DisplayOptions 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 our 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 & DisplayOptions.ShowContainer) > 0)
            {
                // work out namespace
            }

            writer.WriteString(name);

            if ((options & DisplayOptions.ShowTemplates) > 0)
            {
                // work out templates
            }
        }
コード例 #8
0
ファイル: LinkTextResolver.cs プロジェクト: Tyler-Zhou/SHFB
        private string GetTypeTemplateName(SimpleTypeReference type, int position)
        {
            if (targets[type.Id] is TypeTarget target)
            {
                IList <string> templates = target.Templates;

                if (templates.Count > position)
                {
                    return(templates[position]);
                }

                if (target.ContainingType != null)
                {
                    return(GetTypeTemplateName(target.ContainingType, position));
                }

                return("UTT");
            }
            else
            {
                throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
                                                                  "Unknown type reference '{0}'", type.Id));
            }
        }
コード例 #9
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="templateType">The template type</param>
        /// <param name="arguments">The arguments</param>
        public Specialization(SimpleTypeReference templateType, IList <TypeReference> arguments)
        {
            this.TemplateType = templateType ?? throw new ArgumentNullException(nameof(templateType));
            this.Arguments    = arguments ?? throw new ArgumentNullException(nameof(arguments));
        }