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

Add setting to ignore default value checker #121

Open
marius-stanescu opened this issue Oct 2, 2017 · 7 comments · May be fixed by #177
Open

Add setting to ignore default value checker #121

marius-stanescu opened this issue Oct 2, 2017 · 7 comments · May be fixed by #177

Comments

@marius-stanescu
Copy link

I see that GenFu will not write to a property if it doesn't have the default value. I think there should be a setting so we can turn this off if needed.

@JimKay1941
Copy link

Can someone help me understand what is referred to as 'IT' in '...if IT doesn't have...'?

Can someone help me understand the meaning of '...the default value' in this context?

@stimms
Copy link
Collaborator

stimms commented Nov 7, 2017

@JimKay1941 If you're filling an object and the property doesn't have a default value (0 for numerics, null for objects, ...) then GenFu will ignore the property and not fill it. That's what you were seeing in your other issue (#126). The idea here is that we could do

GenFu.Configure<BlogPost>().Fill(x=>x.Tags, 
() => new List<string> { "Azure", "AWS", "Chickens"}, 
ForceFillEvenIfAlreadyFilled = true);

And GenFu would fill the property regardless of it already had a value.

Disclaimer syntax above not the final syntax

@JimKay1941
Copy link

JimKay1941 commented Nov 8, 2017

Don't you find it jarring to have to combine 'new List<string>' and 'ForceFillEvenIfAlreadyFilled = true' in the very same statement?

Perhaps GenFu needs an additional boolean property: 'ForceFillEvenIfEmpty' wouldn't you say?

Though, upon reflection, I don't really understand how/why 'ignore' would EVER be acceptable behavior. When a service routine does NOT do what was requested, it really SHOULD provide some indication. The notion of 'fail silently' annoys me no end.

@stimms
Copy link
Collaborator

stimms commented Nov 8, 2017

Keep in mind that we want to maintain backwards compatibility so this new behaviour cannot be the default. I'd argue that GenFu is doing what is expected, it is filling in missing data. Something like

var person = new Person("bob", "smith");
A.New<Person>(person); //fills in remaining fields

Is a reasonable application of GenFu. I'd also draw your attention to the disclaimer above that this is not a final syntax. I'm certainly willing to entertain other options so please feel free to expand upon your ForceFillEvenIfEmpty idea.

@JimKay1941
Copy link

As a check against developer errors, I may want to differentiate between FillEvenIfAlreadyFilled and FillEvenIfEmpty.

To me, these are entirely different situations.

(Right now, I'm trying to test the latest version that MisterJames submitted as a Pull.)

@stimms
Copy link
Collaborator

stimms commented Nov 8, 2017

FillEvenIfEmpty is the default behaviour now, we'll fill anything that looks like a collection unless it has things in it already.

@JimKay1941
Copy link

I have tested this version by cloning it into a Git Repository.

This version is working now in the same way the Alice version was working.

Thank you for your assistance.

Can you estimate when this update will be available as a Nuget Package?

dylan-smith added a commit to dylan-smith/GenFu that referenced this issue Sep 5, 2024
Fixes MisterJames#121

Add a setting to ignore the default value checker

* Add a new boolean property `IgnoreDefaultValueChecker` to the `GenFu` class in `src/GenFu/GenFu.cs`.
* Modify the `New` method in the `GenFu` class to check the `IgnoreDefaultValueChecker` property before using the `DefaultValueChecker`.
* Add a method to set the `IgnoreDefaultValueChecker` property in the `GenFuConfigurator` class in `src/GenFu/GenFuConfigurator.cs`.
* Add tests in `tests/GenFu.Tests/GenFuTests.cs` to verify the new behavior of ignoring the default value checker.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/MisterJames/GenFu/issues/121?shareId=XXXX-XXXX-XXXX-XXXX).
@dylan-smith dylan-smith linked a pull request Sep 5, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants