/// <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; } }
private string GetTypeTemplateName(SimpleTypeReference type, int position) { TypeTarget target = targets[type.Id] as TypeTarget; if (target != null) { IList <string> templates = target.Templates; if (templates.Count > position) { return(templates[position]); } if (target.ContainingType != null) { return(GetTypeTemplateName(target.ContainingType, position)); } return("UTT"); } else { throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Unknown type reference '{0}'", type.Id)); } }
private static SpecializedTypeReference CreateSpecializedTypeReference(string api) { List <Specialization> specializations = new List <Specialization>(); string text = String.Copy(api); // At the moment we are only handling one specialization; need to iterate int specializationStart = text.IndexOf('{'); int specializationEnd = FindMatchingEndBracket(text, specializationStart); string list = text.Substring(specializationStart + 1, specializationEnd - specializationStart - 1); IList <string> types = SeparateTypes(list); string template = text.Substring(0, specializationStart) + String.Format(CultureInfo.InvariantCulture, "`{0}", types.Count); SimpleTypeReference templateReference = CreateSimpleTypeReference(template); TypeReference[] argumentReferences = new TypeReference[types.Count]; for (int i = 0; i < types.Count; i++) { argumentReferences[i] = CreateTypeReference(types[i]); } Specialization specialization = new Specialization(templateReference, argumentReferences); specializations.Add(specialization); // end iteration return(new SpecializedTypeReference(specializations)); }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="templateType">The template type</param> /// <param name="position">The position</param> public TypeTemplateTypeReference(SimpleTypeReference templateType, int position) { if(templateType == null) throw new ArgumentNullException("templateType"); if(position < 0) throw new ArgumentOutOfRangeException("position"); this.TemplateType = templateType; this.Position = position; }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="templateType">The template type</param> /// <param name="arguments">The arguments</param> public Specialization(SimpleTypeReference templateType, IList<TypeReference> arguments) { if(templateType == null) throw new ArgumentNullException("templateType"); if(arguments == null) throw new ArgumentNullException("arguments"); this.TemplateType = templateType; this.Arguments = arguments; }
private void WriteSimpleType(SimpleTypeReference simple, DisplayOptions options, bool showOuterType, XmlWriter writer) { TypeTarget type = targets[simple.Id] as TypeTarget; if (type != null) { WriteTypeTarget(type, options, showOuterType, writer); } else { TextReferenceUtilities.WriteSimpleTypeReference(simple, options, writer); } }
private static Specialization CreateSpecialization(XPathNavigator node) { SimpleTypeReference template = CreateSimpleTypeReference(node); List <TypeReference> arguments = new List <TypeReference>(); XPathNodeIterator specializationNodes = node.Select("specialization/*"); foreach (XPathNavigator specializationNode in specializationNodes) { arguments.Add(CreateTypeReference(specializationNode)); } return(new Specialization(template, arguments)); }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="templateType">The template type</param> /// <param name="position">The position</param> public TypeTemplateTypeReference(SimpleTypeReference templateType, int position) { if (templateType == null) { throw new ArgumentNullException("templateType"); } if (position < 0) { throw new ArgumentOutOfRangeException("position"); } this.TemplateType = templateType; this.Position = position; }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="templateType">The template type</param> /// <param name="arguments">The arguments</param> public Specialization(SimpleTypeReference templateType, IList <TypeReference> arguments) { if (templateType == null) { throw new ArgumentNullException("templateType"); } if (arguments == null) { throw new ArgumentNullException("arguments"); } this.TemplateType = templateType; this.Arguments = arguments; }
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); } } }
internal static void WriteSimpleTypeReference(SimpleTypeReference type, DisplayOptions options, XmlWriter writer) { // This logic won't correctly deal with nested types, but type CER strings simply don't include that // information, so this is our best guess under the assumption of a non-nested type string cer = type.Id; // Get the name string name; int lastDotPosition = cer.LastIndexOf('.'); if (lastDotPosition > 0) { // Usually, the name will start after the last dot name = cer.Substring(lastDotPosition + 1); } else { // But if there is no dot, this is a type in the default namespace and the name is everything // after the colon. name = cer.Substring(2); } // Remove any generic tics from the name int tickPosition = name.IndexOf('`'); if (tickPosition > 0) { name = name.Substring(0, tickPosition); } if ((options & DisplayOptions.ShowContainer) > 0) { // work out namespace } writer.WriteString(name); if ((options & DisplayOptions.ShowTemplates) > 0) { // work out templates } }
/// <summary> /// Write out a simple type reference /// </summary> /// <param name="simple">The simple type 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 WriteSimpleType(SimpleTypeReference simple, DisplayOptions options, XmlWriter writer) { WriteSimpleType(simple, options, true, writer); }
/// <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 string GetTypeTemplateName(SimpleTypeReference type, int position) { TypeTarget target = targets[type.Id] as TypeTarget; if(target != null) { IList<string> templates = target.Templates; if(templates.Count > position) return templates[position]; if(target.ContainingType != null) return GetTypeTemplateName(target.ContainingType, position); return "UTT"; } else throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Unknown type reference '{0}'", type.Id)); }
private void WriteSimpleType(SimpleTypeReference simple, DisplayOptions options, bool showOuterType, XmlWriter writer) { TypeTarget type = targets[simple.Id] as TypeTarget; if(type != null) { WriteTypeTarget(type, options, showOuterType, writer); } else { TextReferenceUtilities.WriteSimpleTypeReference(simple, options, writer); } }
internal static void WriteSimpleTypeReference(SimpleTypeReference type, DisplayOptions options, XmlWriter writer) { // This logic won't correctly deal with nested types, but type CER strings simply don't include that // information, so this is our best guess under the assumption of a non-nested type string cer = type.Id; // Get the name string name; int lastDotPosition = cer.LastIndexOf('.'); if(lastDotPosition > 0) { // Usually, the name will start after the last dot name = cer.Substring(lastDotPosition + 1); } else { // But if there is no dot, this is a type in the default namespace and the name is everything // after the colon. name = cer.Substring(2); } // Remove any generic tics from the name int tickPosition = name.IndexOf('`'); if(tickPosition > 0) name = name.Substring(0, tickPosition); if((options & DisplayOptions.ShowContainer) > 0) { // work out namespace } writer.WriteString(name); if((options & DisplayOptions.ShowTemplates) > 0) { // work out templates } }
/// <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; } }