示例#1
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="prefix">The prefix</param>
        /// <param name="specializedType">The specialized type</param>
        /// <param name="memberName">The member name</param>
        /// <param name="parameters">The parameters</param>
        public SpecializedMemberWithParametersReference(string prefix, SpecializedTypeReference specializedType,
                                                        string memberName, IList <TypeReference> parameters)
        {
            this.Prefix          = prefix;
            this.SpecializedType = specializedType ?? throw new ArgumentNullException(nameof(specializedType));
            this.MemberName      = memberName;
            this.ParameterTypes  = parameters ?? throw new ArgumentNullException(nameof(parameters));
        }
示例#2
0
        private void WriteSpecializedType(SpecializedTypeReference special, DisplayOptions 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
                {
                    WriteSeparator(writer);
                    WriteSpecialization(specializations[i], options & ~DisplayOptions.ShowContainer, writer);
                }
            }
        }
示例#3
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 (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);
        }
        //=====================================================================

        /// <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));
        }