public static TypeReference ReadTypeReference(XmlReader reader) { if (reader == null || reader.NodeType != XmlNodeType.Element) { return(null); } switch (reader.Name) { // 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); }
private static SpecializedTypeReference CreateSpecializedTypeReference(XPathNavigator node) { Stack <Specialization> specializations = new Stack <Specialization>(); XPathNavigator typeNode = node.Clone(); while (typeNode != null) { specializations.Push(CreateSpecialization(typeNode)); typeNode = typeNode.SelectSingleNode("type"); } SpecializedTypeReference reference = new SpecializedTypeReference(specializations.ToArray()); return(reference); }
private void WriteSpecializedType(SpecializedTypeReference special, ReferenceLinkDisplayOptions 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 { WriteSeperator(writer); WriteSpecialization(specializations[i], options & ~ReferenceLinkDisplayOptions.ShowContainer, writer); } } }
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); } }
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)); } }