public void WriteDiffHtml(ReflectionDumper buffer) { string diffType = $"{Type}"; if (Type == DiffType.Add) { diffType += "e"; } diffType += "d"; if (HasParent) { diffType += " child"; } buffer.OpenClassTag(diffType, stack, "div"); buffer.NextLine(); switch (Type) { case DiffType.Change: { // Check if we should keep this on one line, based on the text version. string textSignature = WriteDiffTxt(); bool multiline = textSignature.Contains(NL); // Write what we changed. buffer.WriteElement("WhatChanged", Field, stack + 1); // Write what was changed. Target.WriteHtml(buffer, stack + 1, false); // Changed From, Changed To. From.WriteHtml(buffer, multiline); To.WriteHtml(buffer, multiline); break; } case DiffType.Rename: { // Write what we're renaming. buffer.OpenClassTag(Field, stack + 1); buffer.WriteElement("String", Target.Name, stack + 2); buffer.CloseClassTag(stack + 1); // Write its new name. To.WriteHtml(buffer); break; } case DiffType.Merge: { // Write the elements that are being merged. From.WriteHtml(buffer, false, 0, new Descriptor.HtmlConfig() { TagType = "li", NumTabs = stack + 2, }); // Write what they merged into. buffer.OpenClassTag("MergeListInto", stack + 1); buffer.NextLine(); To.WriteHtml(buffer, false, 1, new Descriptor.HtmlConfig() { TagType = "li", NumTabs = stack + 3, }); buffer.CloseClassTag(stack + 1); break; } case DiffType.Move: { string descType = Target.DescriptorType; string name = $" {Target.Name}"; buffer.WriteElement(descType, name, stack); From.WriteHtml(buffer, true); To.WriteHtml(buffer, true); break; } default: { string descType = Target.DescriptorType; bool detailed = (Type == DiffType.Add); if (Field != descType) { if (Context != null && Context is Tags) { Tags tags = Context as Tags; string tagClass = "TagChange"; if (tags.Count == 1) { tagClass += " singular"; } if (Type == DiffType.Add) { tagClass += " to"; } else { tagClass += " from"; } buffer.OpenClassTag(tagClass, stack + 1); buffer.NextLine(); tags.WriteHtml(buffer, stack + 2); buffer.CloseClassTag(stack + 1); detailed = false; } else { buffer.WriteElement("Field", Field, stack + 1); } } buffer.OpenClassTag("Target", stack + 1); buffer.NextLine(); Target.WriteHtml(buffer, stack + 2, detailed); buffer.CloseClassTag(stack + 1); break; } } if (children.Count > 0) { children.Sort(); children.ForEach(child => child.WriteDiffHtml(buffer)); } buffer.CloseClassTag(stack, "div"); }
public void WriteHtml(ReflectionDumper buffer, HtmlConfig config = null) { if (config == null) { config = new HtmlConfig(); } int numTabs = config.NumTabs; string tagType = config.TagType; bool detailed = config.Detailed; bool diffMode = config.DiffMode; var tokens = GetTokens(detailed); tokens.Remove("DescriptorType"); string schema = GetSchema(detailed); string tagClass = DescriptorType; if (!diffMode && Tags.Contains("Deprecated")) { tagClass += " deprecated"; // The CSS will strike-through this. } if (!diffMode && DescriptorType != "Class" && DescriptorType != "Enum") { tagClass += " child"; } buffer.OpenClassTag(tagClass, numTabs, tagType); buffer.NextLine(); int search = 0; while (true) { int openToken = schema.IndexOf('{', search); if (openToken < 0) { break; } int closeToken = schema.IndexOf('}', openToken); if (closeToken < 0) { break; } string token = schema.Substring(openToken + 1, closeToken - openToken - 1); if (tokens.ContainsKey(token)) { if (token == "Tags") { Tags.WriteHtml(buffer, numTabs + 1); } else if (token == "Parameters" || token.EndsWith("Type")) { Type type = GetType(); foreach (FieldInfo info in type.GetFields()) { if (info.FieldType == typeof(Parameters) && token == "Parameters") { var parameters = info.GetValue(this) as Parameters; parameters.WriteHtml(buffer, numTabs + 1); break; } else if (info.FieldType == typeof(LuaType) && token.EndsWith("Type")) { var luaType = info.GetValue(this) as LuaType; luaType.WriteHtml(buffer, numTabs + 1); break; } } } else { string value = tokens[token] .ToString() .Replace("<", "<") .Replace(">", ">") .Trim(); if (value.Length > 0) { if (token == "ClassName") { token += " " + DescriptorType; } buffer.WriteElement(token, value, numTabs + 1); } } } search = closeToken + 1; } buffer.CloseClassTag(numTabs, tagType); }