Example #1
0
 private void WriteSimpleMember(SimpleMemberReference member, DisplayOptions options, XmlWriter writer,
                                Dictionary <IndexedTemplateTypeReference, TypeReference> dictionary)
 {
     if (targets[member.Id] is MemberTarget target)
     {
         WriteMemberTarget(target, options, writer, dictionary);
     }
     else
     {
         TextReferenceUtilities.WriteSimpleMemberReference(member, options, writer, this);
     }
 }
        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);
                }
            }
        }
        /// <summary>
        /// Create a member reference
        /// </summary>
        /// <param name="api">The member ID for which to create a reference</param>
        /// <returns>The member reference</returns>
        public static MemberReference CreateMemberReference(string api)
        {
            if (api == null)
            {
                throw new ArgumentNullException(nameof(api));
            }

            if (ValidSimpleMember.IsMatch(api))
            {
                // This is just a normal member of a simple type
                return(new SimpleMemberReference(api));
            }

            if (ValidSpecializedMember.IsMatch(api))
            {
                // This is a member of a specialized type; we need to extract:
                // (1) the underlying specialized type, (2) the member name, (3) the arguments

                // Separate the member prefix
                int    colonPosition = api.IndexOf(':');
                string prefix        = api.Substring(0, colonPosition);
                string text          = api.Substring(colonPosition + 1);

                // Get the arguments
                string arguments = String.Empty;
                int    startParenthesisPosition = text.IndexOf('(');

                if (startParenthesisPosition > 0)
                {
                    int endParenthesisPosition = text.LastIndexOf(')');
                    arguments = text.Substring(startParenthesisPosition + 1, endParenthesisPosition - startParenthesisPosition - 1);
                    text      = text.Substring(0, startParenthesisPosition);
                }

                // Separate the type and member name
                int lastDotPosition;
                int firstHashPosition = text.IndexOf('#');

                if (firstHashPosition > 0)
                {
                    // If this is an EII, the boundary is at the last dot before the hash
                    lastDotPosition = text.LastIndexOf('.', firstHashPosition);
                }
                else
                {
                    // Otherwise, the boundary is at the last dot
                    lastDotPosition = text.LastIndexOf('.');
                }

                string name = text.Substring(lastDotPosition + 1);
                text = text.Substring(0, lastDotPosition);

                // Text now contains a specialized generic type; use it to create a reference
                SpecializedTypeReference type = CreateSpecializedTypeReference("T:" + text);

                // If there are no arguments, we simply create a reference to a member whose identifier we
                // construct in the specialized type.
                if (String.IsNullOrEmpty(arguments))
                {
                    string typeId   = type.Specializations[type.Specializations.Count - 1].TemplateType.Id;
                    string memberId = String.Format(CultureInfo.InvariantCulture, "{0}:{1}.{2}", prefix,
                                                    typeId.Substring(2), name);
                    SimpleMemberReference member = new SimpleMemberReference(memberId);
                    return(new SpecializedMemberReference(member, type));
                }

                // If there are arguments, life is not so simple.  We can't be sure we can identify the
                // corresponding member of the template type because any particular type that appears in
                // the argument might have come from the template or it might have come from the specialization.
                // We need to create a special kind of reference to handle this situation.
                IList <string>  parameterTypeCers = SeparateTypes(arguments);
                TypeReference[] parameterTypes    = new TypeReference[parameterTypeCers.Count];

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

                return(new SpecializedMemberWithParametersReference(prefix, type, name, parameterTypes));
            }

            return(null);
        }
Example #4
0
 private void WriteSimpleMember(SimpleMemberReference member, DisplayOptions options, XmlWriter writer)
 {
     WriteSimpleMember(member, options, writer, null);
 }
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="templateMember">The template member</param>
        /// <param name="specializedType">The specialized type</param>
        public SpecializedMemberReference(SimpleMemberReference templateMember,
                                          SpecializedTypeReference specializedType)
        {
            this.TemplateMember  = templateMember ?? throw new ArgumentNullException(nameof(templateMember));
            this.SpecializedType = specializedType ?? throw new ArgumentNullException(nameof(specializedType));
        }