Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump() does not print out public fields #23

Open
dyster opened this issue Feb 23, 2024 · 3 comments
Open

Dump() does not print out public fields #23

dyster opened this issue Feb 23, 2024 · 3 comments
Assignees

Comments

@dyster
Copy link

dyster commented Feb 23, 2024

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; } }

@MoaidHathot
Copy link
Owner

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;

@dyster
Copy link
Author

dyster commented Feb 23, 2024

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?

@MoaidHathot
Copy link
Owner

MoaidHathot commented Aug 24, 2024

@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 MoaidHathot self-assigned this Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants