Beispiel #1
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
            SimpleTypeReference typeContext = context as SimpleTypeReference;

            if (typeContext != null)
            {
                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
            SimpleMemberReference memberContext = context as SimpleMemberReference;

            if (memberContext != null)
            {
                string typeId, memberName, arguments;
                DecomposeMemberIdentifier(memberContext.Id, out typeId, out memberName, out arguments);
                genericTypeContext = CreateSimpleTypeReference(typeId);
                return;
            }
        }
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="templateMember"></param>
        /// <param name="specializedType"></param>
        public SpecializedMemberReference(SimpleMemberReference templateMember,
          SpecializedTypeReference specializedType)
        {
            if(templateMember == null)
                throw new ArgumentNullException("templateMember");

            if(specializedType == null)
                throw new ArgumentNullException("specializedType");

            this.TemplateMember = templateMember;
            this.SpecializedType = specializedType;
        }
Beispiel #3
0
        private void WriteSimpleMember(SimpleMemberReference member, DisplayOptions options, XmlWriter writer, Dictionary <IndexedTemplateTypeReference, TypeReference> dictionary)
        {
            MemberTarget target = targets[member.Id] as MemberTarget;

            if (target != null)
            {
                WriteMemberTarget(target, options, writer, dictionary);
            }
            else
            {
                TextReferenceUtilities.WriteSimpleMemberReference(member, options, writer, this);
            }
        }
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="templateMember"></param>
        /// <param name="specializedType"></param>
        public SpecializedMemberReference(SimpleMemberReference templateMember,
                                          SpecializedTypeReference specializedType)
        {
            if (templateMember == null)
            {
                throw new ArgumentNullException("templateMember");
            }

            if (specializedType == null)
            {
                throw new ArgumentNullException("specializedType");
            }

            this.TemplateMember  = templateMember;
            this.SpecializedType = specializedType;
        }
        /// <summary>
        /// Create a member reference
        /// </summary>
        /// <param name="node">The node from which to get the target information</param>
        /// <returns>The member reference</returns>
        public static MemberReference CreateMemberReference(XPathNavigator node)
        {
            string api = node.GetAttribute("api", String.Empty);
            SimpleMemberReference member = new SimpleMemberReference(api);

            bool isSpecialized = (bool)node.Evaluate("boolean(./type//specialization)");

            if (isSpecialized)
            {
                XPathNavigator           typeNode = node.SelectSingleNode("type");
                SpecializedTypeReference type     = CreateSpecializedTypeReference(typeNode);

                return(new SpecializedMemberReference(member, type));
            }

            return(member);
        }
Beispiel #6
0
        internal static void WriteSimpleMemberReference(SimpleMemberReference member, DisplayOptions options, XmlWriter writer, LinkTextResolver resolver)
        {
            string cer = member.Id;

            string typeCer, memberName, arguments;

            DecomposeMemberIdentifier(cer, out typeCer, out memberName, out 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 = 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);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Write out a member reference
        /// </summary>
        /// <param name="member">The member 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 WriteMember(MemberReference member, DisplayOptions options, XmlWriter writer)
        {
            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

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

            SimpleMemberReference simple = member as SimpleMemberReference;

            if (simple != null)
            {
                WriteSimpleMember(simple, options, writer);
                return;
            }

            SpecializedMemberReference special = member as SpecializedMemberReference;

            if (special != null)
            {
                WriteSpecializedMember(special, options, writer);
                return;
            }

            SpecializedMemberWithParametersReference ugly = member as SpecializedMemberWithParametersReference;

            if (ugly != null)
            {
                WriteSpecializedMemberWithParameters(ugly, options, writer);
                return;
            }

            throw new InvalidOperationException("Unknown member reference type");
        }
Beispiel #8
0
 private void WriteSimpleMember(SimpleMemberReference member, DisplayOptions options, XmlWriter writer)
 {
     WriteSimpleMember(member, options, writer, null);
 }
        /// <summary>
        /// Create a member reference
        /// </summary>
        /// <param name="node">The node from which to get the target information</param>
        /// <returns>The member reference</returns>
        public static MemberReference CreateMemberReference(XPathNavigator node)
        {
            string api = node.GetAttribute("api", String.Empty);
            SimpleMemberReference member = new SimpleMemberReference(api);

            bool isSpecialized = (bool)node.Evaluate("boolean(./type//specialization)");

            if(isSpecialized)
            {
                XPathNavigator typeNode = node.SelectSingleNode("type");
                SpecializedTypeReference type = CreateSpecializedTypeReference(typeNode);

                return new SpecializedMemberReference(member, type);
            }

            return member;
        }
Beispiel #10
0
        private void WriteSimpleMember(SimpleMemberReference member, DisplayOptions options, XmlWriter writer, Dictionary<IndexedTemplateTypeReference, TypeReference> dictionary)
        {
            MemberTarget target = targets[member.Id] as MemberTarget;

            if(target != null)
                WriteMemberTarget(target, options, writer, dictionary);
            else
                TextReferenceUtilities.WriteSimpleMemberReference(member, options, writer, this);
        }
Beispiel #11
0
 private void WriteSimpleMember(SimpleMemberReference member, DisplayOptions options, XmlWriter writer)
 {
     WriteSimpleMember(member, options, writer, null);
 }
        internal static void WriteSimpleMemberReference(SimpleMemberReference member, DisplayOptions options, XmlWriter writer, LinkTextResolver resolver)
        {
            string cer = member.Id;

            string typeCer, memberName, arguments;
            DecomposeMemberIdentifier(cer, out typeCer, out memberName, out 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 = 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);
                }
            }
        }
        /// <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(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;
        }
Beispiel #14
0
        /// <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 (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);
        }