예제 #1
0
        public static MemberReference ReadMemberReference(XmlReader reader)
        {
            if (reader == null || reader.NodeType != XmlNodeType.Element)
            {
                return(null);
            }

            switch (reader.Name)
            {
            // For the MemberReference(s)...
            case "SimpleMemberReference":
                SimpleMemberReference simpleMemberReference = new SimpleMemberReference();
                simpleMemberReference.ReadXml(reader);
                return(simpleMemberReference);

            case "SpecializedMemberReference":
                SpecializedMemberReference specializedMemberReference = new SpecializedMemberReference();
                specializedMemberReference.ReadXml(reader);
                return(specializedMemberReference);

            case "SpecializedMemberWithParametersReference":
                SpecializedMemberWithParametersReference specializedMemberWithParametersReference
                    = new SpecializedMemberWithParametersReference();
                specializedMemberWithParametersReference.ReadXml(reader);
                return(specializedMemberWithParametersReference);
            }

            return(null);
        }
        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));
            }
        }
        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));
            }
            else
            {
                return(member);
            }
        }
        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);
                }
            }
        }
        public static void SetGenericContext(string cer)
        {
            // re-set the context
            genericTypeContext   = null;
            genericMemberContext = null;

            // get the new context
            Reference context = CreateReference(cer);

            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)
            {
                genericMemberContext = memberContext;

                string typeId, memberName, arguments;
                DecomposeMemberIdentifier(memberContext.Id, out typeId, out memberName, out arguments);
                genericTypeContext = CreateSimpleTypeReference(typeId);
                return;
            }
        }
        public static MemberReference CreateMemberReference(string api)
        {
            if (ValidSimpleMember.IsMatch(api))
            {
                // this is just a normal member of a simple type
                return(new SimpleMemberReference(api));
            }
            else 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

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

                // separator 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("{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);
                IList <TypeReference> parameterTypes    = new List <TypeReference>(parameterTypeCers.Count);
                for (int i = 0; i < parameterTypeCers.Count; i++)
                {
                    parameterTypes.Add(CreateTypeReference(parameterTypeCers[i]));
                }
                return(new SpecializedMemberWithParametersReference(prefix, type, name, parameterTypes));
            }
            else
            {
                return(null);
                //throw new InvalidOperationException(String.Format("Invalid member '{0}'", api));
            }
        }
 private void WriteSimpleMember(SimpleMemberReference member, ReferenceLinkDisplayOptions options, XmlWriter writer)
 {
     WriteSimpleMember(member, options, writer, null);
 }
예제 #8
0
        public static Reference ReadReference(XmlReader reader)
        {
            if (reader == null || reader.NodeType != XmlNodeType.Element)
            {
                return(null);
            }

            switch (reader.Name)
            {
            case "InvalidReference":
                InvalidReference invalidReference = new InvalidReference();
                invalidReference.ReadXml(reader);
                return(invalidReference);

            case "NamespaceReference":
                NamespaceReference namespaceReference = new NamespaceReference();
                namespaceReference.ReadXml(reader);
                return(namespaceReference);

            case "ExtensionMethodReference":
                ExtensionMethodReference extensionMethodReference = new ExtensionMethodReference();
                extensionMethodReference.ReadXml(reader);
                return(extensionMethodReference);

            // For the MemberReference(s)...
            case "SimpleMemberReference":
                SimpleMemberReference simpleMemberReference = new SimpleMemberReference();
                simpleMemberReference.ReadXml(reader);
                return(simpleMemberReference);

            case "SpecializedMemberReference":
                SpecializedMemberReference specializedMemberReference = new SpecializedMemberReference();
                specializedMemberReference.ReadXml(reader);
                return(specializedMemberReference);

            case "SpecializedMemberWithParametersReference":
                SpecializedMemberWithParametersReference specializedMemberWithParametersReference
                    = new SpecializedMemberWithParametersReference();
                specializedMemberWithParametersReference.ReadXml(reader);
                return(specializedMemberWithParametersReference);

            // For the TypeReference(s)...
            case "SimpleTypeReference":
                SimpleTypeReference simpleTypeReference = new SimpleTypeReference();
                simpleTypeReference.ReadXml(reader);
                return(simpleTypeReference);

            case "SpecializedTypeReference":
                SpecializedTypeReference specializedTypeReference = new SpecializedTypeReference();
                specializedTypeReference.ReadXml(reader);
                return(specializedTypeReference);

            case "ArrayTypeReference":
                ArrayTypeReference arrayTypeReference = new ArrayTypeReference();
                arrayTypeReference.ReadXml(reader);
                return(arrayTypeReference);

            case "ReferenceTypeReference":
                ReferenceTypeReference referenceTypeReference = new ReferenceTypeReference();
                referenceTypeReference.ReadXml(reader);
                return(referenceTypeReference);

            case "PointerTypeReference":
                PointerTypeReference pointerTypeReference = new PointerTypeReference();
                pointerTypeReference.ReadXml(reader);
                return(pointerTypeReference);

            // For the TemplateTypeReference(s)...
            case "IndexedTemplateTypeReference":
                IndexedTemplateTypeReference indexedTemplateTypeReference =
                    new IndexedTemplateTypeReference();
                indexedTemplateTypeReference.ReadXml(reader);
                return(indexedTemplateTypeReference);

            case "NamedTemplateTypeReference":
                NamedTemplateTypeReference namedTemplateTypeReference = new NamedTemplateTypeReference();
                namedTemplateTypeReference.ReadXml(reader);
                return(namedTemplateTypeReference);

            case "TypeTemplateTypeReference":
                TypeTemplateTypeReference typeTemplateTypeReference = new TypeTemplateTypeReference();
                typeTemplateTypeReference.ReadXml(reader);
                return(typeTemplateTypeReference);

            case "MethodTemplateTypeReference":
                MethodTemplateTypeReference methodTemplateTypeReference = new MethodTemplateTypeReference();
                methodTemplateTypeReference.ReadXml(reader);
                return(methodTemplateTypeReference);
            }

            return(null);
        }