[工具推荐]Dumpify --通过向控制台应用程序添加扩展方法来提高工作效率和可调试性

2023-10-17 15:16:36 浏览数 (2)

VS插件Dumpify

代码语言:javascript复制
dotnet add package Dumpify --version 0.6.0

特征

  • 以结构化、彩色的方式将任何对象转储到控制台、调试、跟踪或任何其他自定义输出
  • 支持属性、字段和非公共成员
  • 支持最大嵌套级别
  • 支持循环依赖和引用
  • 支持样式和自定义
  • 高度可配置
  • 支持不同的输出目标:控制台、跟踪、调试、文本、自定义
  • 快!

例子:

匿名类型

代码语言:javascript复制
new { Name = "Dumpify", Description = "Dump any object to Console" }.Dump();
支持嵌套和循环引用
代码语言:javascript复制
var moaid = new Person { FirstName = "Moaid", LastName = "Hathot", Profession = Profession.Software };
var haneeni = new Person { FirstName = "Haneeni", LastName = "Shibli", Profession = Profession.Health };

moaid.Spouse = haneeni;
haneeni.Spouse = moaid;

moaid.Dump();
//You can define max depth as well, e.g `moaid.Dump(maxDepth: 2)`
支持数组、字典和集合
代码语言:javascript复制
var arr = new[] { 1, 2, 3, 4 }.Dump();
代码语言:javascript复制
var arr2d = new int[,] { {1, 2}, {3, 4} }.Dump();
代码语言:javascript复制
new Dictionary<string, string>
{
    ["Moaid"] = "Hathot",
    ["Haneeni"] = "Shibli",
    ["Eren"] = "Yeager",
    ["Mikasa"] = "Ackerman",
}.Dump();
您可以打开或关闭字段和私有成员
代码语言:javascript复制
public class AdditionValue
{
    private readonly int _a;
    private readonly int _b;

    public AdditionValue(int a, int b)
    {
        _a = a;
        _b = b;
    }

    private int Value => _a   _b;
}


new AdditionValue(1, 2).Dump(members: new MembersConfig { IncludeFields = true, IncludeNonPublicMembers = true });
您可以自定义颜色
代码语言:javascript复制
var package = new { Name = "Dumpify", Description = "Dump any object to Console" };
package.Dump(colors: ColorConfig.NoColors);
package.Dump(colors: new ColorConfig { PropertyValueColor = new DumpColor(Color.RoyalBlue)});
您可以打开或关闭类型名称,标题,标签等
代码语言:javascript复制
var moaid = new Person { FirstName = "Moaid", LastName = "Hathot", Profession = Profession.Software };
var haneeni = new Person { FirstName = "Haneeni", LastName = "Shibli", Profession = Profession.Health };
moaid.Spouse = haneeni;
haneeni.Spouse = moaid;

moaid.Dump(typeNames: new TypeNamingConfig { ShowTypeNames = false }, tableConfig: new TableConfig { ShowTableHeaders = false });
有多个输出选项(控制台、跟踪、调试、文本)或提供您自己的输出选项
代码语言:javascript复制
var package = new { Name = "Dumpify", Description = "Dump any object to Console" };
package.Dump(); //Similar to `package.DumpConsole()` and `package.Dump(output: Outputs.Console))`
package.DumpDebug(); //Dump to Visual Studio's Debug source
package.DumpTrace(); //Dump to Trace 
var text = package.DumpText(); //The table in a text format

using var writer = new StringWriter();
package.Dump(output: new DumpOutput(writer)); //Custom output
每个配置都可以按转储定义,也可以为所有转储全局定义,例如:
代码语言:javascript复制
DumpConfig.Default.TypeNamingConfig.UseAliases = true;
DumpConfig.Default.TypeNamingConfig.ShowTypeNames = false;
DumpConfig.Default.ColorConfig.TypeNameColor = Color.Gold;
DumpConfig.Default.MaxDepth = 3;
//Much more...

0 人点赞