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

Overriding defaults set in constructor #43

Open
Quantumplation opened this issue Jun 23, 2015 · 3 comments
Open

Overriding defaults set in constructor #43

Quantumplation opened this issue Jun 23, 2015 · 3 comments

Comments

@Quantumplation
Copy link
Contributor

I'm not sure how you would solve this, but if you set some field in your constructor, Dossier overrides it with what it thinks should be the default. This is particularly annoying with collections, since the default Dossier chooses is to set collection properties to null, rather than an empty collection. The workaround we're using is to override BuildObject and call .Set(GetOrDefault() ?? EmptyCollection) on every collection field.

Some possible solutions that I see:

  • Some way to indicate that Dossier should skip certain fields, unless someone's called Set on them
  • Make all fields opt-in, and provide an easy way to say "give this a sensible default"
  • Read the value of a field first, and if it's not the default value for that field, then set it to some reasonable default
  • Change the handling so that an empty list is the default for ICollection properties, Enumerable.Empty is the default for IEnumerable properties, etc.
@robdmoore
Copy link
Member

You should be able to register a global value provider that looks for a collection and returns an empty collection.

The next question would be whether that's something that should be in the default list or not...

@SupernaviX
Copy link

I think that would make sense as a default, as long as it was possible to remove. Would it make sense to fill collections with anonymous values too, at least for simple types like ints or strings?

@robdmoore
Copy link
Member

On reflection to avoid breaking changes I'd like to keep the current default, but I think there is value in providing anonymous value suppliers to do both things so that the user can decide to add them to the global (or local) suppliers.

Do either of you want to have a go at adding anonymous value suppliers for your suggestions?

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

3 participants