Dumpify icon indicating copy to clipboard operation
Dumpify copied to clipboard

Dump() does not print out public fields

Open dyster opened this issue 1 year ago • 3 comments

if you create a public class with public fields like public class MyClass { public uint MyNumber; } and call Dump() on it you just get an empty table with the header but if you change the fields to properties it will work, i.e public class MyClass { public uint MyNumber { get; set; } }

dyster avatar Feb 23 '24 23:02 dyster

Hi @dyster, this feature is actually available but is turned-off by default, so you need to enable it. You can do that either globally (for all Dumps) or on per-dump basis. Enabling it globally:

DumpConfig.Default.MembersConfig.IncludeFields = true;

Enabling it on per-dump basis:

new Test().Dump(members: new MembersConfig { IncludeFields = true });

Btw, you can include nonpublic members as well, example:

DumpConfig.Default.MembersConfig.IncludeNonePublicMembers = true;

MoaidHathot avatar Feb 23 '24 23:02 MoaidHathot

Yes I just branched the code to have a look and realised quickly there was a MembersConfig where I could set it. My next thought on that was then is that the correct default behaviour? Followed by well, if you follow good practice then you should not have public fields on your class so maybe it shouldn't be the default (I was only fooling around with some test code). Followed again by, well, what does it do when you use public fields on a struct?

Which I just tried and no it does not print public fields by default, but that is (I think at least) how you are normally supposed to use structs? So should the default behaviour be different for a class or a struct, and should the MembersConfig also differentiate between the two?

dyster avatar Feb 23 '24 23:02 dyster

@dyster, sorry about the delay in my response. I agree with you that we should consider changing the default behavior with structs and once that is done, we should find a better way to separate the class/struct behaviors.

I think the configuration model we have now is not ideal and I'm open for ideas on how to improve it

MoaidHathot avatar Aug 24 '24 07:08 MoaidHathot