public static string GetMarkupTypeName(Type t) { if (TypeAliases.TryGetValue(t, out var name)) { return($"`{name}`"); } if (t.IsEnum) { return($"[{t.Name}](../Enums/{t.Name}.md)"); } if (!t.IsGenericType) { return($"`{t.Name}`"); } if (t.GetGenericTypeDefinition() == typeof(Nullable <>)) { var underlyingType = Nullable.GetUnderlyingType(t); if (underlyingType == null) { return(t.Name); } return(GetMarkupTypeName(underlyingType) + "?"); } var typeName = t.Name.Split("`")[0]; var arguments = $"<{string.Join(",", t.GetGenericArguments().Select(GetMarkupTypeName))}>"; return(typeName + arguments); }
public void TestGetTemplateArgumentsNestedOneTwo() { var result = TypeAliases.GetTemplateArguments("Windows.Foundation.Collections.IVector`1<Windows.Foundation.Collections.IMap`2<System.Int32,System.Int32>>"); Assert.IsNotNull(result); Assert.AreEqual(1, result.Length); Assert.AreEqual("Windows.Foundation.Collections.IMap`2<System.Int32,System.Int32>", result[0]); }
public void TestGetTemplateArgumentsHandleSpaces() { var result = TypeAliases.GetTemplateArguments("Windows.Foundation.Collections.IMap`2< Windows.Foundation.Collections.IVector`1<System.Int32>, Windows.Foundation.Collections.IVector`1<System.Int32> >"); Assert.IsNotNull(result); Assert.AreEqual(2, result.Length); Assert.AreEqual("Windows.Foundation.Collections.IVector`1<System.Int32>", result[0]); Assert.AreEqual("Windows.Foundation.Collections.IVector`1<System.Int32>", result[1]); }
public string GetFullIndexTitle(IEntity entity) { var dataType = (DataType)entity; var ns = dataType.FindNamespace(); var title = TypeAliases.HasAlias(dataType.QualifiedName) ? GetIndexTitleInternal(entity, true) : ns.FullName + "." + GetIndexTitleInternal(entity, true); return(title); }
static bool IsParentNamespaceInContextNamespaces(DataType dataType, ICollection <string> namespaceDeclarations) { if (dataType.Parent == null || dataType.Parent.NamescopeType != NamescopeType.Namespace) { return(false); } return(dataType.Parent.IsRoot || namespaceDeclarations.Contains(dataType.Parent.FullName) || TypeAliases.HasAlias(dataType.QualifiedName)); }
IEnumerable <SuggestItem> ConvertNamescopesToSuggestions(IEnumerable <Namescope> dataTypes) { return(dataTypes.Select(d => { var itemType = SuggestItemType.Class; if (d is Namespace) { itemType = SuggestItemType.Namespace; } return SuggestionHelper.Suggest(itemType, d, TypeAliases.HasAlias(d.QualifiedName) ? d.FullName : d.Name); })); }
/// <summary> /// 遍历当前XML节点 /// </summary> /// <param name="xnav">XPathNavigator对象</param> protected override void ParseChild(XmlReader xnav) { if (null == xnav) { return; } switch (xnav.Name) { case "properties": { break; } case "settings": { ParseChilds(xnav, "settings", "setting", Settings); //while (xnav.Read()) //{ // if (xnav.NodeType == XmlNodeType.EndElement && xnav.Name == "settings") // { // break; // } // if (xnav.Name == "setting") // { // Settings.Add(new XSetting(xnav)); // } //} break; } case "typeAliases": { while (xnav.Read()) { if (xnav.NodeType == XmlNodeType.EndElement && xnav.Name == "typeAliases") { break; } if (xnav.Name == "typeAlias") { TypeAliases.Add(new XTypeAlias(xnav)); } } break; } } }
public string Resolve(string typeName) { string aliasedTypeName; if (!TypeAliases.TryGetAliasFromType(typeName, out aliasedTypeName)) { aliasedTypeName = typeName; } //if (aliasedTypeName.Contains("`")) // aliasedTypeName = aliasedTypeName.BeforeFirst("`") + "<" + new string(',', int.Parse(aliasedTypeName.AfterFirst("`"))-1) + ">"; string cilType; if (_cilTypeMap.TryGetValue(aliasedTypeName, out cilType)) { return(cilType); } return(typeName); }
public static string DataTypeToHtmlString(DataType dt, IEnumerable <string> usings) { if (dt == null) { return(""); } string type; if (TypeAliases.TryGetTypeFromAlias(dt.FullName, out type)) { return("<span style=\"color: blue;\">" + dt.FullName + "</span>"); } string name = SafeXml(dt.ToString()); foreach (var u in usings.OrderByDescending((s) => s.Length)) { if (name.StartsWith(u)) { name = name.Substring(Math.Min(name.Length, u.Length + 1)); break; } } var p = name.LastIndexOf('.') + 1; if (p == 0) { return("<span style=\"color: green;\">" + name + "</span>"); } else { var head = name.Substring(0, p); var tail = name.Substring(p); return(head + "<span style=\"color: green;\">" + tail + "</span>"); } }
/// <summary> /// Creates an XML string containing an unmerged view of the <see cref="T:System.Configuration.ConfigurationSection"/> object as a single section to write to a file. /// </summary> /// <returns> /// An XML string containing an unmerged view of the <see cref="T:System.Configuration.ConfigurationSection"/> object. /// </returns> /// <param name="parentElement">The <see cref="T:System.Configuration.ConfigurationElement"/> instance to use as the parent when performing the un-merge. /// </param><param name="name">The name of the section to create. /// </param><param name="saveMode">The <see cref="T:System.Configuration.ConfigurationSaveMode"/> instance to use when writing to a string. /// </param> protected override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode) { ExtensionElementMap.Clear(); currentSection = this; TypeResolver.SetAliases(this); InitializeSectionExtensions(); var sb = new StringBuilder(); using (var writer = MakeXmlWriter(sb)) { writer.WriteStartElement(name, XmlNamespace); writer.WriteAttributeString("xmlns", XmlNamespace); TypeAliases.SerializeElementContents(writer, "alias"); Namespaces.SerializeElementContents(writer, "namespace"); Assemblies.SerializeElementContents(writer, "assembly"); SectionExtensions.SerializeElementContents(writer, "sectionExtension"); Containers.SerializeElementContents(writer, "container"); writer.WriteEndElement(); } return(sb.ToString()); }
private string GetTypeAlias(Type type) { return(TypeAliases.GetOrAddEx(type, BuildAlias)); }
public static string CreateHtmlHint(object obj, ICompiler compiler, IEnumerable <string> usings) { var documentation = ""; if (obj is Entity) { var doc = DocumentationCache.GetEntry(obj as Entity); if (doc != null && doc.Documentation != null && doc.Documentation.Length > 0) { var fullDoc = doc.Documentation.Replace("@", ""); documentation = "<br />" + StripHTML(fullDoc) + "<br /><br /><em>Press F1 for more documentation</em>"; } LastHintedEntity = obj as Entity; } if (obj is GetMetaProperty) { var rmp = obj as GetMetaProperty; return(DataTypeToHtmlString(rmp.ReturnType, usings) + " " + rmp.Name + " " + Color("<em>(meta property)</em>", "gray") + documentation); } else if (obj is InvalidExpression) { return(null); } else if (obj is ClassType) { var dt = obj as ClassType; return(Keyword("class") + " " + SafeXml(dt.QualifiedName) + documentation); } else if (obj is Namespace) { var dt = obj as Namespace; return(Keyword("namespace ") + " " + SafeXml(dt.QualifiedName) + documentation); } else if (obj is string) { string type; if (TypeAliases.TryGetTypeFromAlias(obj as string, out type)) { var s = compiler.ILFactory.GetEntity(Source.Unknown, type); return((s != null ? (CreateHtmlHint(s, compiler, usings) ?? "") : "") + "<br /><br /><em><strong>" + obj as string + "</strong> is a type alias for " + SafeXml(type) + "</em>"); } return(Keyword(SafeXml(obj as string)) + " (keyword)"); } else if (obj is StructType) { var dt = obj as StructType; return(Keyword("struct") + " " + SafeXml(dt.QualifiedName) + documentation); } else if (obj is InterfaceType) { var dt = obj as InterfaceType; return(Keyword("interface") + " " + SafeXml(dt.QualifiedName) + documentation); } else if (obj is DelegateType) { var dt = obj as DelegateType; return(Keyword("delegate") + " " + SafeXml(dt.ToString()) + documentation); } else if (obj is EnumType) { var dt = obj as EnumType; return(Keyword("enum") + " " + SafeXml(dt.QualifiedName) + documentation); } else if (obj is Variable) { var v = obj as Variable; return(DataTypeToHtmlString(v.ValueType, usings) + " " + SafeXml(v.Name) + " (local variable)"); } else if (obj is Block) { var b = obj as Block; return(SafeXml(b.Name) + " (meta property block)" + documentation); } else if (obj is Parameter) { var p = obj as Parameter; return(DataTypeToHtmlString(p.Type, usings) + " " + SafeXml(p.Name) + " (method argument)"); } else if (obj is GenericParameterType) { var gpt = obj as GenericParameterType; if (gpt.IsGenericMethodParameter) { return(SafeXml(gpt.ToString()) + " : generic parameter type of method " + SafeXml(gpt.GenericMethodParent.ToString())); } else { return(SafeXml(gpt.ToString()) + " : generic parameter type of type " + SafeXml(gpt.GenericTypeParent.ToString())); } } else { var usingList = usings as IList <string> ?? usings.ToList(); if (obj is Property) { var p = obj as Property; return (DataTypeToHtmlString(p.ReturnType, usingList) + " " + DataTypeToHtmlString(p.DeclaringType, usingList) + "." + p.Name + " { " + (p.GetMethod != null && p.GetMethod.Body != null ? "get; " : "") + (p.SetMethod != null && p.SetMethod.Body != null ? "set; " : "") + "} " + documentation); } else if (obj is Field) { var f = obj as Field; return (DataTypeToHtmlString(f.ReturnType, usingList) + " " + DataTypeToHtmlString(f.DeclaringType, usingList) + "." + f.Name + documentation); } else if (obj is Constructor) { var c = obj as Constructor; string s = "("; foreach (var arg in c.Parameters) { if (arg != c.Parameters[0]) { s += ", "; } s += DataTypeToHtmlString(arg.Type, usingList) + " " + arg.Name; if (arg.OptionalDefault != null) { s += " = " + SafeXml(arg.OptionalDefault.ToString()); } } s += ")"; var overloads = c.DeclaringType.Constructors.Count; if (overloads > 1) { s += Color(" <em>(+" + (overloads - 1) + " overloads)</em>", "gray"); } return (DataTypeToHtmlString(c.ReturnType, usingList) + " " + DataTypeToHtmlString(c.DeclaringType, usingList) + s + documentation); } else if (obj is Method) { var m = obj as Method; string s = "("; foreach (var arg in m.Parameters) { if (arg != (m as Method).Parameters[0]) { s += ", "; } s += DataTypeToHtmlString(arg.Type, usingList) + " " + arg.Name; if (arg.OptionalDefault != null) { s += " = " + SafeXml(arg.OptionalDefault.ToString()); } } s += ")"; var overloads = 0; var bt = m.DeclaringType; while (bt != null) { foreach (var om in bt.Methods) { if (om.Name == m.Name) { overloads++; } } bt = bt.Base; } if (overloads > 1) { s += Color(" <em>(+" + (overloads - 1) + " overloads)</em>", "gray"); } return (DataTypeToHtmlString(m.ReturnType, usingList) + " " + DataTypeToHtmlString(m.DeclaringType, usingList) + "." + SafeXml(m.Name) + s + documentation); } else if (obj is MetaProperty) { return(CreateHtmlHint(obj as MetaProperty, usingList, null)); } else if (obj is FileEntity) { return(SafeXml((obj as FileEntity).Path) + " <em>(external file)</em>"); } else if (obj is DirectoryEntity) { return(SafeXml((obj as FileEntity).Path) + " <em>(external directory)</em>"); } } if (obj == null) { return(null); } return(documentation); }
public static string AliasOrName(this Type type) { return(TypeAliases.ContainsKey(type) ? TypeAliases[type] : type.Name); }
string GetDataTypeName(DataType dataType) { string name; return(TypeAliases.TryGetAliasFromType(dataType.QualifiedName, out name) ? name : dataType.Name); }
public static string Alias(this Type type) { return(TypeAliases.ContainsKey(type) ? TypeAliases[type] : string.Empty); }
public string FindMemberExpression(out TokenType terminatingToken, bool inTypeBody, bool skipToFirstPeriod = true) { var offset = _reader.Offset; int firstPeriod = skipToFirstPeriod ? -1 : offset; Func <string> value = () => { _reader.ReadToken(); if (firstPeriod != -1) { var s = _reader.ReadText(firstPeriod - _reader.Offset).Trim(); _reader.Offset = offset; return(_memberExpression = s); } else { _reader.Offset = offset; return(_memberExpression = ""); } }; int scopes = 0; int parens = 0; int triangleParens = 0; var tokenHistory = new List <TokenType>(); while (true) { var t = _reader.ReadTokenReverse(); tokenHistory.Add(t); switch (t) { case TokenType.Period: { if (firstPeriod == -1) { firstPeriod = _reader.Offset; continue; } } break; case TokenType.RightSquareBrace: case TokenType.RightParen: { if (parens == 0) { var o2 = _reader.Offset; _reader.ReadToken(); var t2 = _reader.ReadToken(); _reader.Offset = o2; if (t2 != TokenType.Period && t2 != TokenType.LeftSquareBrace) { terminatingToken = t; return(value()); } } parens++; } continue; case TokenType.LeftSquareBrace: case TokenType.LeftParen: { if (parens == 0) { terminatingToken = t; return(value()); } --parens; continue; } case TokenType.RightCurlyBrace: { if (inTypeBody || parens == 0) { terminatingToken = t; return(value()); } scopes++; continue; } case TokenType.LeftCurlyBrace: { if (scopes == 0) { terminatingToken = t; return(value()); } scopes--; } break; case TokenType.New: case TokenType.Import: case TokenType.Static: case TokenType.Using: case TokenType.Comma: case TokenType.Assign: case TokenType.Plus: case TokenType.Minus: case TokenType.Mul: case TokenType.Div: case TokenType.Mod: case TokenType.AddAssign: case TokenType.MinusAssign: case TokenType.MulAssign: case TokenType.DivAssign: case TokenType.ModAssign: case TokenType.NotEqual: case TokenType.Equal: case TokenType.LessOrEqual: case TokenType.GreaterOrEqual: case TokenType.LogAnd: case TokenType.LogOr: case TokenType.ExclamationMark: case TokenType.BitwiseAnd: case TokenType.BitwiseOr: case TokenType.BitwiseXor: case TokenType.BitwiseAndAssign: case TokenType.BitwiseOrAssign: case TokenType.BitwiseXorAssign: { if (scopes == 0 && parens == 0) { terminatingToken = t; return(value()); } } break; case TokenType.GreaterThan: { if (triangleParens > 0 || (tokenHistory.Count > 1 && tokenHistory[tokenHistory.Count - 2] == TokenType.Period)) { ++triangleParens; } else { if (scopes == 0 && parens == 0) { terminatingToken = t; return(value()); } } } break; case TokenType.LessThan: { if (triangleParens > 0) { triangleParens--; } else { if (scopes == 0 && parens == 0) { terminatingToken = t; return(value()); } } } break; case TokenType.Colon: case TokenType.Semicolon: { if (scopes == 0) { terminatingToken = t; return(value()); } } break; case TokenType.EndOfFile: terminatingToken = t; return(""); case TokenType.This: break; case TokenType.Identifier: { var w = _reader.PeekTokenReverse(); if (scopes == 0 && parens == 0 && w == TokenType.Whitespace) { _reader.ReadTokenReverse(); w = _reader.PeekTokenReverse(); if (scopes == 0 && parens == 0 && (w == TokenType.Identifier || TypeAliases.HasAlias(w.ToLiteral()))) { terminatingToken = t; return(value()); } _reader.ReadToken(); var o2 = _reader.Offset; t = _reader.ReadToken(); var t1 = _reader.PeekToken(); _reader.Offset = o2; if (t1 == TokenType.LeftParen) { _reader.ReadTokenReverse(); terminatingToken = t; return(value()); } } } break; default: { if (Tokens.IsReserved(t.ToLiteral())) { if (scopes == 0 && parens == 0) { terminatingToken = t; return(value()); } } } break; } } }
string GetPageBaseNameForConstructor(DataType context) { string name; return(TypeAliases.TryGetAliasFromType(context.QualifiedName, out name) ? name : context.Name); }