4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C#でdumpするライブラリ MemberValueを作ってみた

Posted at

C#でdumpするライブラリ MemberValueを作ってみました。
https://github.com/oo2kazuma/MemberValue

説明

C#にはオブジェクトの詳細を文字列でダンプする方法が備わっていません。
このライブラリはこれを可能にするものです。
どんなオブジェクトでもそのクラスのToStringメソッドに依存することなく自動で各フィールド・メソッドの値を文字列出力します。
デバッグログでご利用ください。

最新DLLファイル

https://github.com/oo2kazuma/MemberValue/releases/tag/0.9.8
・MemberValue.dll
・MemberValue.XML

Example

Code

    private void NewMethod()
    {
        var dumper = new OHLibrary.MemberValue("TestClassObject", new TestClass());
        Console.WriteLine(dumper.Dump());
    }

    public class TestClass
    {
        public string StringValue="StringValue";
        public int IntValue = 1;
    }

Result

Name[TestClassObject] Value[WindowsFormsApplication1.Form1+TestClass] Type[WindowsFormsApplication1.Form1+TestClass] ThrewException[False]
-Name[StringValue] Value[StringValue] Type[System.String] ThrewException[False]
-Name[IntValue] Value[1] Type[System.Int32] ThrewException[False]

作成した経緯

プロダクト環境でオブジェクトの詳細な状態を見たかった。
しかし、自作クラスが多いプロジェクトでそれぞれのクラスのToStringメソッドをオーバーライドする労力は膨大。
なら、各フィールドを自動検知してその値を出力できるライブラリを作れば幸せになれるのでは。。
ということで作りました。

ライセンス

MITです。
ご利用の際は、利用者から見える画面、または同梱ファイルに下記の文字列を記載してください。

MIT License
Copyright (c) 2016 oo2kazuma
https://github.com/oo2kazuma/MemberValue/blob/master/LICENCE
4
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?