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

[Enhancement] Object Dumper to C# - make it detect what default constructor does #130

Open
ishepherd opened this issue Aug 27, 2024 · 2 comments

Comments

@ishepherd
Copy link

Generated C# calls the default constructor but it doesn't know what the constructor does.

Is it feasible (!!) for Object Dumper to call the constructor to find out the initial state, and make the right calls for desired state?

Example

Let's say the dumped object has property string A, and the value is null

  • If the constructor has A = "";
    • Then Object Dumper would generate A = null;
  • But if the constructor does not set A
    • Then Object Dumper wouldn't set A
@thomasgalliker
Copy link
Owner

I don‘t understand what you mean. ObjectDumper just traverses properties of an already constructed object and dumps content as c# initializer code.

If you can provide some sample code (objects to be dumped) and a simple unit test then I can look into it.

@ishepherd
Copy link
Author

Thanks for your reply.
Yes I know. And this feature is unreasonable to ask. (btw - Thanks for creating this project 😄)

Here was my case, approximately

class A {
    string Prop1 {get; set;} = "";
    string Prop2 {get; set;}
}

var x = new A { Prop1 = null };

I think Object Dumper would dump like this, depending on configuration:

// Incorrect.
// Prop1 will be ""
var x = new A();

// Correct, but not minimal.
var x = new A() { Prop1 = null, Prop2 = null }

Some perfect-world Object Dumper could dump it as

// Understands what the constructor does and overrides it
var x = new A { Prop1 = null };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants