public TypeDocumentation(TypeDefinition typeDefinition, PackageTargetFramework framework, PackageAssemblyXmlDocs xmlDocs, Lazy <ICSharpCode.Decompiler.CSharp.CSharpDecompiler> decompiler, Lazy <ICSharpCode.Decompiler.CSharp.CSharpDecompiler> idecompiler, ICSharpCode.Decompiler.CSharp.OutputVisitor.CSharpFormattingOptions format) { this.xmlDocs = xmlDocs; this.typeDefinition = typeDefinition; this.framework = framework; this.decompiler = decompiler; this.idecompiler = idecompiler; this.format = format; SummaryHtml = ""; SummaryText = ""; DocumentationHtml = ""; if (xmlDocs != null) { var tn = typeDefinition.GetXmlName(); if (xmlDocs.MemberDocs.TryGetValue(tn, out var td)) { SummaryHtml = XmlToHtml(td.SummaryXml); SummaryText = XmlToText(td.SummaryXml); if (ignoreSummaryTextRe.IsMatch(SummaryHtml)) { SummaryHtml = ""; SummaryText = ""; } } } var w = new StringWriter(); WriteDocumentation(w); DocumentationHtml = w.ToString(); }
public static string GetPrototypeHtml(this IMemberDefinition member, PackageTargetFramework framework, MemberXmlDocs docs, bool linkToCode, bool inExtensionClass) { using (var w = new StringWriter()) { WritePrototypeHtml(member, w, framework, docs, linkToCode, inExtensionClass); return(w.ToString()); } }
public static string GetPrototypeHtml(this IMemberDefinition member, PackageTargetFramework framework, bool linkToCode) { using (var w = new StringWriter()) { WritePrototypeHtml(member, w, framework, linkToCode); return(w.ToString()); } }
static string GetHref(IMemberDefinition member, PackageTargetFramework framework, bool linkToCode) { var url = GetUrl(member, framework, linkToCode); if (string.IsNullOrEmpty(url)) { return(""); } return("href=\"" + url + "\""); }
public static string GetUrl(this IMemberDefinition member, PackageTargetFramework framework, bool linkToCode) { var url = framework.FindTypeUrl(member.DeclaringType); if (string.IsNullOrEmpty(url)) { return(""); } if (linkToCode && framework.Package.AllowedToDecompile) { url += "?code=true"; } if (member is TypeDefinition t && !t.IsNested) { return(url); } return(url + "#" + Uri.EscapeDataString(member.GetXmlName())); }
public void Add(PackageTargetFramework framework, PackageAssembly a, TypeDefinition m, string name, string parent, string type, string id, bool isPublic, int s) { if (results.Count >= maxResults) { return; } var dir = a.IsBuildAssembly ? "build" : "lib"; var code = isPublic ? "" : (framework.Package.AllowedToDecompile ? "?code=true" : ""); var link = $"/packages/{Uri.EscapeDataString(package.Id)}/{Uri.EscapeDataString(package.Version.ShortVersionString)}/{framework.Moniker}/{dir}/{Uri.EscapeDataString(a.FileName)}/{Uri.EscapeDataString(m.Namespace)}/{Uri.EscapeDataString(m.Name)}{code}#{Uri.EscapeDataString(id)}"; results.TryAdd(link, new PackageSearchResult { Name = name, Parent = parent, Type = type, Link = link, IsPublic = isPublic, Score = s, }); }
async Task <PackageAssembly> TryResolveInFrameworkAsync( AssemblyNameReference name, PackageTargetFramework framework, ConcurrentDictionary <string, bool> searchedPackages, ConcurrentQueue <PackageAssembly> found) { var a = framework.Assemblies.FirstOrDefault(x => { // System.Console.WriteLine("HOW ABOUT? " + x.Definition.Name); return(x.Definition.Name.Name == name.Name); }); if (a != null) { found.Enqueue(a); return(a); } if (found.Count > 0) { return(null); } var tasks = new List <Task <PackageAssembly> > (); int Order(PackageDependency d) => d.PackageId.StartsWith("System.", StringComparison.Ordinal) ? 1 : 0; foreach (var d in framework.Dependencies.OrderBy(Order)) { tasks.Add(TryResolveInDependencyAsync(name, d, searchedPackages, found)); } if (found.Count > 0) { return(null); } var results = await Task.WhenAll(tasks).ConfigureAwait(false); return(results.FirstOrDefault(x => x != null)); }
public static void WritePrototypeHtml(this MethodDefinition member, TextWriter w, PackageTargetFramework framework, MemberXmlDocs docs, bool linkToCode, bool inExtensionClass) { if (!member.DeclaringType.IsInterface) { if (member.IsFamily || member.IsFamilyOrAssembly) { w.Write("<span class=\"c-kw\">protected</span> "); } else if (member.IsPublic) { w.Write("<span class=\"c-kw\">public</span> "); } if (member.IsStatic) { w.Write("<span class=\"c-kw\">static</span> "); } } var id = member.GetXmlName(); var href = GetHref(member, framework, linkToCode); if (member.IsConstructor) { w.Write($"<a {href} id=\"{id}\" class=\"c-cd\">"); var name = member.DeclaringType.Name; var ni = name.LastIndexOf('`'); if (ni > 0) { name = name.Substring(0, ni); } WriteEncoded(name, w); } else { if (!member.DeclaringType.IsInterface) { if (member.IsAbstract) { w.Write("<span class=\"c-kw\">abstract</span> "); } else if (member.IsVirtual) { if (member.IsReuseSlot) { w.Write("<span class=\"c-kw\">override</span> "); } else if (!member.IsFinal) { w.Write("<span class=\"c-kw\">virtual</span> "); } } } WriteReferenceHtml(member.ReturnType, w, framework); w.Write($" <a {href} id=\"{id}\" class=\"c-md\">"); WriteEncoded(member.Name, w); } w.Write("</a>"); var head = ""; if (member.HasGenericParameters) { WriteGenericParameterListHtml(member.GenericParameters, w, framework, docs); } w.Write("("); head = ""; bool isExtensionMethod = inExtensionClass && member.HasExtensionAttribute(); foreach (var p in member.Parameters) { w.Write(head); WriteReferenceHtml(p.ParameterType, w, framework, p.IsOut, isExtensionMethod); w.Write(" <span class=\"c-ar\" title=\""); WriteEncoded(docs != null && docs.ParametersText.TryGetValue(p.Name, out var paramText) ? paramText : string.Empty, w); w.Write("\">"); WriteEncoded(p.Name, w); w.Write("</span>"); if (p.HasConstant) { w.Write(" = "); var constant = p.Constant; if (constant == null && p.ParameterType.IsValueType) { w.Write("<span class=\"c-nl\">default</span>"); } else { TypeDocumentation.WritePrimitiveHtml(constant, w); } } head = ", "; isExtensionMethod = false; } w.Write(")"); if (member.HasGenericParameters) { WriteGenericConstraintsHtml(member.GenericParameters, w, framework); } }
public static void WritePrototypeHtml(this IMemberDefinition member, TextWriter w, PackageTargetFramework framework, bool linkToCode) { switch (member) { case FieldDefinition t: WritePrototypeHtml(t, w, framework, linkToCode); break; case MethodDefinition t: WritePrototypeHtml(t, w, framework, linkToCode); break; case PropertyDefinition t: WritePrototypeHtml(t, w, framework, linkToCode); break; case EventDefinition t: WritePrototypeHtml(t, w, framework, linkToCode); break; case TypeDefinition t: WritePrototypeHtml(t, w, framework, linkToCode); break; default: throw new NotSupportedException(member.GetType() + " " + member.FullName); } }
public static void WritePrototypeHtml(this TypeDefinition member, TextWriter w, PackageTargetFramework framework, bool linkToCode) { if (member.IsNestedFamily || member.IsNestedFamilyOrAssembly) { w.Write("<span class=\"c-kw\">protected</span> "); } else if (member.IsPublic || member.IsNestedPublic) { w.Write("<span class=\"c-kw\">public</span> "); } if (member.IsSealed && member.IsAbstract) { w.Write("<span class=\"c-kw\">static</span> "); } else if (member.IsSealed && !member.IsEnum && !member.IsValueType) { w.Write("<span class=\"c-kw\">sealed</span> "); } else if (member.IsAbstract && !member.IsInterface) { w.Write("<span class=\"c-kw\">abstract</span> "); } if (member.IsEnum) { w.Write("<span class=\"c-kw\">enum</span> "); } else if (member.IsValueType) { w.Write("<span class=\"c-kw\">struct</span> "); } else if (member.IsInterface) { w.Write("<span class=\"c-kw\">interface</span> "); } else if (member.IsDelegate()) { w.Write("<span class=\"c-kw\">delegate</span> "); } else { w.Write("<span class=\"c-kw\">class</span> "); } var id = member.GetXmlName(); var name = member.Name; var ni = name.LastIndexOf('`'); if (ni > 0) { name = name.Substring(0, ni); } var url = framework?.FindTypeUrl(member); if (url != null) { w.Write($"<a id=\"{id}\" href=\"{url}\" class=\"c-td\">"); WriteEncoded(name, w); w.Write("</a>"); } else { w.Write($"<span id=\"{id}\" class=\"c-td\">"); WriteEncoded(name, w); w.Write("</span>"); } if (member.HasGenericParameters) { w.Write("<"); var head = ""; foreach (var a in member.GenericParameters) { w.Write(head); WriteReferenceHtml(a, w, framework); head = ", "; } w.Write(">"); } var hier = ((!member.IsEnum && !member.IsValueType && member.BaseType != null && member.BaseType.FullName != "System.Object") ? new[] { member.BaseType } : new TypeReference[0]) .Concat(member.Interfaces.Select(x => x.InterfaceType)).ToList(); if (hier.Count > 0) { w.Write(" : "); var head = ""; foreach (var h in hier) { w.Write(head); WriteReferenceHtml(h, w, framework); head = ", "; } } }
public static void WritePrototypeHtml(this EventDefinition member, TextWriter w, PackageTargetFramework framework, bool linkToCode) { if (!member.DeclaringType.IsInterface) { if (member.AddMethod != null && (member.AddMethod.IsFamily || member.AddMethod.IsFamilyOrAssembly)) { w.Write("<span class=\"c-kw\">protected</span> "); } else if (member.AddMethod != null && (member.AddMethod.IsPublic)) { w.Write("<span class=\"c-kw\">public</span> "); } if (member.AddMethod != null && member.AddMethod.IsStatic) { w.Write("<span class=\"c-kw\">static</span> "); } } w.Write("<span class=\"c-kw\">event</span> "); WriteReferenceHtml(member.EventType, w, framework); var id = member.GetXmlName(); var href = GetHref(member, framework, linkToCode); w.Write($" <a {href} id=\"{id}\" class=\"c-ed\">"); WriteEncoded(member.Name, w); w.Write("</a>"); }
public static void WritePrototypeHtml(this PropertyDefinition member, TextWriter w, PackageTargetFramework framework, bool linkToCode) { if (member.GetMethod != null && !member.DeclaringType.IsInterface) { if ((member.GetMethod.IsFamily || member.GetMethod.IsFamilyOrAssembly)) { w.Write("<span class=\"c-kw\">protected</span> "); } else if ((member.GetMethod.IsPublic)) { w.Write("<span class=\"c-kw\">public</span> "); } if (member.GetMethod.IsStatic) { w.Write("<span class=\"c-kw\">static</span> "); } else if (member.GetMethod.IsAbstract) { w.Write("<span class=\"c-kw\">abstract</span> "); } else if (member.GetMethod.IsVirtual) { if (member.GetMethod.IsReuseSlot) { w.Write("<span class=\"c-kw\">override</span> "); } else if (!member.GetMethod.IsFinal) { w.Write("<span class=\"c-kw\">virtual</span> "); } } } WriteReferenceHtml(member.PropertyType, w, framework); var id = member.GetXmlName(); var href = GetHref(member, framework, linkToCode); if (member.GetMethod != null && member.GetMethod.Parameters.Count > 0) { w.Write($" <a {href} id=\"{id}\" class=\"c-pd\">this</a>["); var head = ""; foreach (var p in member.GetMethod.Parameters) { w.Write(head); WriteReferenceHtml(p.ParameterType, w, framework); w.Write(" <span class=\"c-ar\">"); WriteEncoded(p.Name, w); w.Write("</span>"); head = ", "; } w.Write("]"); } else { w.Write($" <a {href} id=\"{id}\" class=\"c-pd\">"); WriteEncoded(member.Name, w); w.Write("</a>"); } w.Write(" {"); if (member.GetMethod != null) { w.Write(" <span class=\"c-kw\">get</span>;"); } if (member.SetMethod != null) { if (member.SetMethod.IsPublic) { w.Write(" <span class=\"c-kw\">set</span>;"); } else if (member.SetMethod.IsFamily || member.SetMethod.IsFamilyOrAssembly) { w.Write(" <span class=\"c-kw\">protected set</span>;"); } } w.Write(" }"); }
public static void WritePrototypeHtml(this MethodDefinition member, TextWriter w, PackageTargetFramework framework, bool linkToCode) { if (!member.DeclaringType.IsInterface) { if (member.IsFamily || member.IsFamilyOrAssembly) { w.Write("<span class=\"c-kw\">protected</span> "); } else if (member.IsPublic) { w.Write("<span class=\"c-kw\">public</span> "); } if (member.IsStatic) { w.Write("<span class=\"c-kw\">static</span> "); } } var id = member.GetXmlName(); var href = GetHref(member, framework, linkToCode); if (member.IsConstructor) { w.Write($"<a {href} id=\"{id}\" class=\"c-cd\">"); var name = member.DeclaringType.Name; var ni = name.LastIndexOf('`'); if (ni > 0) { name = name.Substring(0, ni); } WriteEncoded(name, w); } else { if (!member.DeclaringType.IsInterface) { if (member.IsAbstract) { w.Write("<span class=\"c-kw\">abstract</span> "); } else if (member.IsVirtual) { if (member.IsReuseSlot) { w.Write("<span class=\"c-kw\">override</span> "); } else if (!member.IsFinal) { w.Write("<span class=\"c-kw\">virtual</span> "); } } } WriteReferenceHtml(member.ReturnType, w, framework); w.Write($" <a {href} id=\"{id}\" class=\"c-md\">"); WriteEncoded(member.Name, w); } w.Write("</a>"); var head = ""; if (member.HasGenericParameters) { w.Write("<"); head = ""; foreach (var p in member.GenericParameters) { w.Write(head); WriteReferenceHtml(p, w, framework); head = ", "; } w.Write(">"); } w.Write("("); head = ""; foreach (var p in member.Parameters) { w.Write(head); WriteReferenceHtml(p.ParameterType, w, framework, p.IsOut); w.Write(" <span class=\"c-ar\">"); WriteEncoded(p.Name, w); w.Write("</span>"); if (p.HasConstant) { w.Write(" = "); TypeDocumentation.WritePrimitiveHtml(p.Constant, w); } head = ", "; } w.Write(")"); }
public static void WriteReferenceHtml(this TypeReference type, TextWriter w, PackageTargetFramework framework, bool isOut = false) { if (type.FullName == "System.Void") { w.Write("<span class=\"c-tr\">void</span>"); } else if (type.FullName == "System.String") { w.Write("<span class=\"c-tr\">string</span>"); } else if (type.FullName == "System.Object") { w.Write("<span class=\"c-tr\">object</span>"); } else if (type.FullName == "System.Decimal") { w.Write("<span class=\"c-tr\">decimal</span>"); } else if (type.IsPrimitive) { w.Write("<span class=\"c-tr\">"); switch (type.FullName) { case "System.Byte": w.Write("byte"); break; case "System.Boolean": w.Write("bool"); break; case "System.Char": w.Write("char"); break; case "System.Double": w.Write("double"); break; case "System.Int16": w.Write("short"); break; case "System.Int32": w.Write("int"); break; case "System.Int64": w.Write("long"); break; case "System.Single": w.Write("float"); break; case "System.SByte": w.Write("sbyte"); break; case "System.UInt16": w.Write("ushort"); break; case "System.UInt32": w.Write("uint"); break; case "System.UInt64": w.Write("ulong"); break; default: WriteEncoded(type.Name, w); break; } w.Write("</span>"); } else if (type.IsArray) { var at = (ArrayType)type; WriteReferenceHtml(at.ElementType, w, framework); w.Write("["); var head = ""; foreach (var d in at.Dimensions) { w.Write(head); head = ","; } w.Write("]"); } else if (type.IsGenericInstance) { GenericInstanceType gi = (GenericInstanceType)type; if (gi.ElementType.FullName == "System.Nullable`1") { WriteReferenceHtml(gi.GenericArguments[0], w, framework); w.Write("?"); } else { WriteReferenceHtml(gi.ElementType, w, framework); w.Write("<"); var head = ""; foreach (var a in gi.GenericArguments) { w.Write(head); WriteReferenceHtml(a, w, framework); head = ", "; } w.Write(">"); } } else if (type.IsByReference) { if (isOut) { w.Write("<span class=\"c-kw\">out</span> "); } else { w.Write("<span class=\"c-kw\">ref</span> "); } WriteReferenceHtml(type.GetElementType(), w, framework); } else { var name = type.Name; var ni = name.LastIndexOf('`'); if (ni > 0) { name = name.Substring(0, ni); } var url = framework?.FindTypeUrl(type); if (url != null) { w.Write($"<a href=\"{url}\" class=\"c-tr\">"); WriteEncoded(name, w); w.Write("</a>"); } else { w.Write("<span class=\"c-tr\">"); WriteEncoded(name, w); w.Write("</span>"); } } }
private static void WriteGenericParameterListHtml(Collection <GenericParameter> genericParameters, TextWriter w, PackageTargetFramework framework) { w.Write("<"); var head = ""; foreach (var p in genericParameters) { w.Write(head); WriteReferenceHtml(p, w, framework); head = ", "; } w.Write(">"); }
public PackageAssemblyResolver(string packageId, PackageTargetFramework packageTargetFramework) { this.packageId = packageId; this.packageTargetFramework = packageTargetFramework; }
public HtmlWriter(TextWriter w, PackageTargetFramework framework) { this.w = w; this.framework = framework; }
private static void WriteGenericParameterListHtml(Collection <GenericParameter> genericParameters, TextWriter w, PackageTargetFramework framework, MemberXmlDocs docs) { w.Write("<"); var head = ""; foreach (var p in genericParameters) { w.Write(head); w.Write("<span class=\"c-tr\" title=\""); WriteEncoded(docs != null && docs.TypeParametersText.TryGetValue(p.Name, out var paramText) ? paramText : string.Empty, w); w.Write("\">"); WriteEncoded(p.Name, w); w.Write("</span>"); head = ", "; } w.Write(">"); }
void Read(MemoryStream bytes, HttpClient httpClient) { SizeInBytes = bytes.Length; Archive = new ZipArchive(bytes, ZipArchiveMode.Read); TargetFrameworks.Clear(); ZipArchiveEntry nuspecEntry = null; foreach (var e in Archive.Entries.Where(x => x.Name != "_._").OrderBy(x => x.FullName)) { var n = e.FullName; var isBuild = n.StartsWith("build/", StringComparison.InvariantCultureIgnoreCase); var isLib = n.StartsWith("lib/", StringComparison.InvariantCultureIgnoreCase); if ((isBuild || isLib) && (n.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) || n.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase) || n.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase))) { var parts = n.Split('/', StringSplitOptions.RemoveEmptyEntries); string tfm; if (parts.Length >= 3) { tfm = Uri.UnescapeDataString(parts[1].Trim().ToLowerInvariant()); } else { tfm = "net"; } var tf = TargetFrameworks.FirstOrDefault(x => x.Moniker == tfm); if (tf == null) { tf = new PackageTargetFramework(this, httpClient) { Moniker = tfm, }; TargetFrameworks.Add(tf); } if (n.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase)) { var docs = new PackageAssemblyXmlDocs(e); if (string.IsNullOrEmpty(docs.Error)) { // System.Console.WriteLine(docs.AssemblyName); tf.AssemblyXmlDocs[docs.AssemblyName] = docs; } } else if (isBuild) { tf.BuildAssemblies.Add(new PackageAssembly(e, tf)); } else { tf.Assemblies.Add(new PackageAssembly(e, tf)); } } else if (n.EndsWith(".nuspec", StringComparison.InvariantCultureIgnoreCase)) { nuspecEntry = e; } else if (n.StartsWith("content/", StringComparison.InvariantCultureIgnoreCase)) { Content.Add(new PackageFile(e)); } else if (n.StartsWith("tools/", StringComparison.InvariantCultureIgnoreCase)) { Tools.Add(new PackageFile(e)); } else { // System.Console.WriteLine(e); } } if (nuspecEntry != null) { ReadNuspec(nuspecEntry); } TargetFrameworks.Sort((a, b) => string.Compare(a.Moniker, b.Moniker, StringComparison.Ordinal)); }
public PackageAssembly(Entry entry, PackageTargetFramework framework) : base(entry) { this.framework = framework; definition = new Lazy <AssemblyDefinition> (() => { try { var ms = new MemoryStream((int)ArchiveEntry.Length); using (var es = entry.Open()) { es.CopyTo(ms); ms.Position = 0; } return(AssemblyDefinition.ReadAssembly(ms, new ReaderParameters { AssemblyResolver = framework.AssemblyResolver, })); } catch (Exception ex) { Debug.WriteLine("Failed to load assembly"); Debug.WriteLine(ex); return(null); } }, true); format = ICSharpCode.Decompiler.CSharp.OutputVisitor.FormattingOptionsFactory.CreateMono(); format.SpaceBeforeMethodCallParentheses = false; format.SpaceBeforeMethodDeclarationParentheses = false; format.SpaceBeforeConstructorDeclarationParentheses = false; format.PropertyBraceStyle = ICSharpCode.Decompiler.CSharp.OutputVisitor.BraceStyle.EndOfLine; format.PropertyGetBraceStyle = ICSharpCode.Decompiler.CSharp.OutputVisitor.BraceStyle.EndOfLine; format.PropertySetBraceStyle = ICSharpCode.Decompiler.CSharp.OutputVisitor.BraceStyle.EndOfLine; format.AutoPropertyFormatting = ICSharpCode.Decompiler.CSharp.OutputVisitor.PropertyFormatting.ForceOneLine; format.SimplePropertyFormatting = ICSharpCode.Decompiler.CSharp.OutputVisitor.PropertyFormatting.ForceOneLine; format.IndentPropertyBody = false; format.IndexerDeclarationClosingBracketOnNewLine = ICSharpCode.Decompiler.CSharp.OutputVisitor.NewLinePlacement.SameLine; format.IndexerClosingBracketOnNewLine = ICSharpCode.Decompiler.CSharp.OutputVisitor.NewLinePlacement.SameLine; format.NewLineAferIndexerDeclarationOpenBracket = ICSharpCode.Decompiler.CSharp.OutputVisitor.NewLinePlacement.SameLine; format.NewLineAferIndexerOpenBracket = ICSharpCode.Decompiler.CSharp.OutputVisitor.NewLinePlacement.SameLine; idecompiler = new Lazy <ICSharpCode.Decompiler.CSharp.CSharpDecompiler> (() => { var m = Definition?.MainModule; if (m == null) { return(null); } return(new ICSharpCode.Decompiler.CSharp.CSharpDecompiler(m, new ICSharpCode.Decompiler.DecompilerSettings { ShowXmlDocumentation = false, ThrowOnAssemblyResolveErrors = false, AlwaysUseBraces = false, CSharpFormattingOptions = format, ExpandMemberDefinitions = false, DecompileMemberBodies = false, UseExpressionBodyForCalculatedGetterOnlyProperties = true, })); }, true); decompiler = new Lazy <ICSharpCode.Decompiler.CSharp.CSharpDecompiler> (() => { var m = Definition?.MainModule; if (m == null) { return(null); } return(new ICSharpCode.Decompiler.CSharp.CSharpDecompiler(m, new ICSharpCode.Decompiler.DecompilerSettings { ShowXmlDocumentation = false, ThrowOnAssemblyResolveErrors = false, AlwaysUseBraces = false, CSharpFormattingOptions = format, ExpandMemberDefinitions = true, DecompileMemberBodies = true, UseExpressionBodyForCalculatedGetterOnlyProperties = true, })); }, true); }
async Task ReadAsync(HttpClient httpClient, string packageUri) { this.Client = httpClient; var entries = await ReadEntriesAsync(httpClient, packageUri); TargetFrameworks.Clear(); Content.Clear(); Tools.Clear(); Entry nuspecEntry = null; foreach (var e in entries.Where(x => Path.GetFileName(x.FullName) != "_._").OrderBy(x => x.FullName)) { var n = e.FullName; var isBuild = n.StartsWith("build/", StringComparison.InvariantCultureIgnoreCase); var isLib = n.StartsWith("lib/", StringComparison.InvariantCultureIgnoreCase); if ((isBuild || isLib) && (n.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) || n.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase) || n.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase))) { var parts = n.Split('/', StringSplitOptions.RemoveEmptyEntries); string tfm; if (parts.Length >= 3) { tfm = Uri.UnescapeDataString(parts[1].Trim().ToLowerInvariant()); } else { tfm = "net"; } var tf = TargetFrameworks.FirstOrDefault(x => x.Moniker == tfm); if (tf == null) { tf = new PackageTargetFramework(this, httpClient) { Moniker = tfm, }; TargetFrameworks.Add(tf); } if (n.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase)) { var docs = new PackageAssemblyXmlLanguageDocs(e); if (string.IsNullOrEmpty(docs.Error)) { // System.Console.WriteLine(docs.AssemblyName); if (!tf.AssemblyXmlDocs.TryGetValue(docs.AssemblyName, out var allLanguageDocs)) { allLanguageDocs = new PackageAssemblyXmlDocs(docs.AssemblyName); tf.AssemblyXmlDocs[docs.AssemblyName] = allLanguageDocs; } allLanguageDocs.AddLanguage(docs.LanguageCode, docs); } } else if (isBuild) { tf.BuildAssemblies.Add(new PackageAssembly(e, tf)); } else { tf.Assemblies.Add(new PackageAssembly(e, tf)); } } else if (n.EndsWith(".nuspec", StringComparison.InvariantCultureIgnoreCase)) { nuspecEntry = e; } else if (n.StartsWith("content/", StringComparison.InvariantCultureIgnoreCase)) { Content.Add(new PackageFile(e)); } else if (n.StartsWith("tools/", StringComparison.InvariantCultureIgnoreCase)) { Tools.Add(new PackageFile(e)); } else { // System.Console.WriteLine(e); } } if (nuspecEntry != null) { ReadNuspec(nuspecEntry); } TargetFrameworks.Sort((a, b) => string.Compare(a.Moniker, b.Moniker, StringComparison.Ordinal)); }
public static void WritePrototypeHtml(this FieldDefinition member, TextWriter w, PackageTargetFramework framework, bool linkToCode) { if (!member.DeclaringType.IsEnum) { if (member.IsFamily || member.IsFamilyOrAssembly) { w.Write("<span class=\"c-kw\">protected</span> "); } else if (member.IsPublic) { w.Write("<span class=\"c-kw\">public</span> "); } if (member.HasConstant) { w.Write("<span class=\"c-kw\">const</span> "); } else { if (member.IsStatic) { w.Write("<span class=\"c-kw\">static</span> "); } if (member.IsInitOnly) { w.Write("<span class=\"c-kw\">readonly</span> "); } } WriteReferenceHtml(member.FieldType, w, framework); w.Write(" "); } var id = member.GetXmlName(); var href = GetHref(member, framework, linkToCode); w.Write($"<a {href} id=\"{id}\" class=\"c-fd\">"); WriteEncoded(member.Name, w); w.Write("</a>"); if (member.HasConstant) { w.Write(" = "); TypeDocumentation.WritePrimitiveHtml(member.Constant, w); } }
private static void WriteGenericConstraintsHtml(Collection <GenericParameter> genericParameters, TextWriter w, PackageTargetFramework framework) { foreach (var p in genericParameters) { if (p.HasConstraints) { w.Write(" where "); WriteReferenceHtml(p, w, framework); w.Write(" : "); var head = ""; foreach (var c in p.Constraints) { if (c.FullName == "System.Object") { w.Write("class"); head = ", "; break; } else if (c.FullName == "System.ValueType") { w.Write("struct"); head = ", "; break; } } foreach (var c in p.Constraints) { if (c.FullName != "System.ValueType" && c.FullName != "System.Object") { w.Write(head); WriteReferenceHtml(c, w, framework); head = ", "; } } } } }
public ApiDiff(PackageData package, PackageTargetFramework framework, PackageData otherPackage, PackageTargetFramework otherFramework) { this.Package = package; this.Framework = framework; this.OtherPackage = otherPackage; this.OtherFramework = otherFramework; if (otherFramework == null) { Error = $"Could not find framework matching \"{framework?.Moniker}\" in {otherPackage?.Id} {otherPackage?.Version}."; return; } var asmDiff = OtherFramework.PublicAssemblies.Diff(Framework.PublicAssemblies, (x, y) => x.Definition.Name.Name == y.Definition.Name.Name); var types = new List <TypeDiffInfo> (); foreach (var aa in asmDiff.Actions) { IEnumerable <Tuple <TypeDefinition, PackageTargetFramework> > srcTypes; IEnumerable <Tuple <TypeDefinition, PackageTargetFramework> > destTypes; switch (aa.ActionType) { case ListDiffActionType.Add: srcTypes = Enumerable.Empty <Tuple <TypeDefinition, PackageTargetFramework> > (); destTypes = aa.DestinationItem.PublicTypes.Select(x => Tuple.Create(x, Framework)); break; case ListDiffActionType.Remove: srcTypes = aa.SourceItem.PublicTypes.Select(x => Tuple.Create(x, OtherFramework)); destTypes = Enumerable.Empty <Tuple <TypeDefinition, PackageTargetFramework> > (); break; default: srcTypes = aa.SourceItem.PublicTypes.Select(x => Tuple.Create(x, OtherFramework)); destTypes = aa.DestinationItem.PublicTypes.Select(x => Tuple.Create(x, Framework)); break; } if (aa.ActionType == ListDiffActionType.Remove) { continue; } var typeDiff = srcTypes.Diff(destTypes, (x, y) => x.Item1.FullName == y.Item1.FullName); foreach (var ta in typeDiff.Actions) { var ti = new TypeDiffInfo { Action = ta.ActionType }; IEnumerable <IMemberDefinition> srcMembers; IEnumerable <IMemberDefinition> destMembers; switch (ta.ActionType) { case ListDiffActionType.Add: ti.Type = ta.DestinationItem.Item1; ti.Framework = ta.DestinationItem.Item2; srcMembers = Enumerable.Empty <IMemberDefinition> (); destMembers = ti.Type.GetPublicMembers(); break; case ListDiffActionType.Remove: ti.Type = ta.SourceItem.Item1; ti.Framework = ta.SourceItem.Item2; srcMembers = ti.Type.GetPublicMembers(); destMembers = Enumerable.Empty <IMemberDefinition> (); break; default: ti.Type = ta.DestinationItem.Item1; ti.Framework = ta.DestinationItem.Item2; srcMembers = ta.SourceItem.Item1.GetPublicMembers(); destMembers = ta.DestinationItem.Item1.GetPublicMembers(); break; } if (ta.ActionType == ListDiffActionType.Remove) { types.Add(ti); continue; } var memDiff = srcMembers.Diff(destMembers, (x, y) => x.FullName == y.FullName); foreach (var ma in memDiff.Actions) { var mi = new MemberDiffInfo { Action = ma.ActionType }; switch (ma.ActionType) { case ListDiffActionType.Add: mi.Member = ma.DestinationItem; ti.Members.Add(mi); break; case ListDiffActionType.Remove: mi.Member = ma.SourceItem; ti.Members.Add(mi); break; default: mi.Member = ma.DestinationItem; break; } } if (ta.ActionType == ListDiffActionType.Add || ti.Members.Count > 0) { types.Add(ti); } } } foreach (var ns in types.GroupBy(x => x.Type.Namespace)) { var ni = new NamespaceDiffInfo { Action = ListDiffActionType.Update }; ni.Namespace = ns.Key; ni.Types.AddRange(ns); Namespaces.Add(ni); } Namespaces.Sort((x, y) => string.Compare(x.Namespace, y.Namespace, StringComparison.Ordinal)); }
Task <PackageAssembly> TryResolveInFrameworkAsync(AssemblyNameReference name, PackageTargetFramework packageTargetFramework, ConcurrentDictionary <string, bool> searchedPackages, CancellationTokenSource cts) { var a = packageTargetFramework.Assemblies.FirstOrDefault(x => { // System.Console.WriteLine("HOW ABOUT? " + x.Definition.Name); return(x.Definition.Name.Name == name.Name); }); if (a != null) { return(Task.FromResult(a)); } int Order(PackageDependency d) => d.PackageId.StartsWith("System.") ? 1 : 0; var gotResultCS = new TaskCompletionSource <PackageAssembly> (); var tasks = new List <Task <PackageAssembly> > (); foreach (var d in packageTargetFramework.Dependencies.OrderBy(Order)) { tasks.Add(TryResolveInDependencyAsync(name, d, searchedPackages, cts).ContinueWith(t => { if (t.IsCompletedSuccessfully && t.Result != null) { gotResultCS.TrySetResult(t.Result); cts.Cancel(); return(t.Result); } return(null); })); } var allCompleteTask = Task.WhenAll(tasks); var anythingTask = Task.WhenAny(new[] { (Task)gotResultCS.Task }.Append(allCompleteTask)); return(anythingTask.ContinueWith(t => { // System.Console.WriteLine("DONE RESOLVING IN " + packageTargetFramework.Moniker); if (gotResultCS.Task.IsCompletedSuccessfully) { return gotResultCS.Task.Result; } return null; })); }