UseConstructor(), SkipConstructor() and fixing StrictMode() error #338
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@bchavez Promised PR from #334
➕ Adding features for specifying constructors:
UseConstructor()
andSkipConstructor()
UseConstructor() also provide overload for specifying if paremeterless constructor is private/protected
U have already discussed if this should be in Bogus here: Using Faker[T] with private constructor and private property setter #213 - i think it makes sense to to have this feature because using SkipConstructor() is way more shady then asking users if they want use hidden constructor
Usage:
UseConstructor()
to use public parameterless ctorUseConstructor(false)
to use public parameterless ctorUseConstructor(true)
to use private/protected parameterless ctorUseConstructor(x=>new Instance())
to use custom delegate (CustomInstantiator()
marked as obsolete)SkipConstructor()
to not using constructor at allWhen parameterless ctor is not found the NoParameterlessCtorException is thrown
🔧 Found & Fixed bug when StrictMode(true) is used and no RuleFor() is specified
⚠️ .net standard 1.3 is missing few methods so
NotSupportedException
is thrown istead in this assemblySorry for using different code formatted in advanced ... 😃
Also question is it necessery to have T in Faker[T] to be reference type? Because i would consider generating structures handy and looking very briefly i didn't see any reason why it would not be possible