Bogus
Bogus copied to clipboard
UseConstructor(), SkipConstructor() and fixing StrictMode() error
@bchavez Promised PR from #334
➕ Adding features for specifying constructors: UseConstructor()
and SkipConstructor()
-
UseConstructor() also provide overload for specifying if paremeterless constructor is private/protected U have already discussed if this should be in Bogus here: #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 all
When parameterless ctor is not found the NoParameterlessCtorException<T> 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 assembly
Sorry 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
@Basyras Thank you for the PR. I really appreciate it! I'll try to provide my thoughts below.
-
Please try to revert formatting changes. Please only change what is minimally necessary. Reviewing this PR is extremely difficult because of the formatting changes. Code merged into Bogus should be production quality and goes through a strict review process because, ultimately, I have to maintain it.
-
Keep the code focused on the new feature only. That is, the PR should only be adding
.SkipConstructor()
that usesGetUninitializedObject
. -
If you see a bug, the bug fix should be in a separate PR, not merged with a new feature PR. It's too difficult to track and revert if there is a problem with the bug and fix.
If you can, please break up the PR. There are too many changes in this PR. I will try to dedicate more time for this during the holiday break.
Thanks, Brian
@bchavez Shared formatting rules from .editorconfig file were not applied. I can see .editorconfig file in your root folder but i think your formatting rules are not inside. That's the reason why my formatting changes were made. Could you fix that? Should be simple, go to your IDE formatting settings and on top there should be option to generate .editorconfig
What ever happened to this PR, I don't seem to see it ever made it into the code ?
@gl1tch nope