//===================================================================== /// <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> /// 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) { if(specializedType == null) throw new ArgumentNullException("specializedType"); if(parameters == null) throw new ArgumentNullException("parameters"); this.Prefix = prefix; this.SpecializedType = specializedType; this.MemberName = memberName; this.ParameterTypes = parameters; }
//===================================================================== /// <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; }
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); } } }
/// <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); }
//===================================================================== /// <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) { if (specializedType == null) { throw new ArgumentNullException("specializedType"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } this.Prefix = prefix; this.SpecializedType = specializedType; this.MemberName = memberName; this.ParameterTypes = parameters; }
/// <summary> /// Write out a type reference /// </summary> /// <param name="type">The type reference information</param> /// <param name="options">The link display options</param> /// <param name="writer">The write to which the information is written</param> /// <param name="dictionary">The template type dictionary</param> private void WriteType(TypeReference type, DisplayOptions options, XmlWriter writer, Dictionary <IndexedTemplateTypeReference, TypeReference> dictionary) { if (type == null) { throw new ArgumentNullException("type"); } if (writer == null) { throw new ArgumentNullException("writer"); } SimpleTypeReference simple = type as SimpleTypeReference; if (simple != null) { WriteSimpleType(simple, options, writer); return; } SpecializedTypeReference specialized = type as SpecializedTypeReference; if (specialized != null) { WriteSpecializedType(specialized, options, writer); return; } ArrayTypeReference array = type as ArrayTypeReference; if (array != null) { WriteArrayType(array, options, writer, dictionary); return; } ReferenceTypeReference reference = type as ReferenceTypeReference; if (reference != null) { WriteReferenceType(reference, options, writer, dictionary); return; } PointerTypeReference pointer = type as PointerTypeReference; if (pointer != null) { WritePointerType(pointer, options, writer, dictionary); return; } TemplateTypeReference template = type as TemplateTypeReference; if (template != null) { WriteTemplateType(template, options, writer, dictionary); return; } throw new InvalidOperationException("Unknown type reference type"); }
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); } }
/// <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); }