Open Gakk opened 1 year ago
Great find. Thank you for bringing this to my attention. I agree this should be fixed.
The compiler already does the enforcement of the [Obsolete("", true)]
object property by failing compilation. There's no need for Bogus to complain about the property and there's no reason for Bogus to ask the user to do something that would result in a failed compilation anyway.
You can create a PR for this, but if you take on this task; please:
[Obsolete("", true)]
and [Obsolete("", false)]
Binder
object which is responsible for getting a projected view of an object's properties that Bogus uses for validation.
Currently, workarounds for v34.0.2
and below are:
.Ignore("SomeOldProperty");
as originally reported CustomBinder : Binder
and overriding CustomBinder.GetMembers()
with the necessary fix to filter out properties that would contain [Obsolete("", true)]
.
Please describe why you are requesting a feature
When the object you are trying to fake has an obsolete property marked to generate compile error, the validation to ensure all properties have rules fails:
Since this property is marked to generate a compile time error, I belive it should have been ignored by default, as has already been implemented for readonly properties in v3.0.6 with #13 Strict mode problem with read only property.
There is now way to generate or get data for this obsolete property, so I believe it should be safe to silently ignore it.
Please provide a code example of what you are trying to achieve
My class has this properties:
The key here is the argument
true
on the obsolete property.When creating a new faker this will fail with the mentioned
ValidationException
for the obsolete property:One way to work around this is using the
Ignore
statementThis ignore has to be done by property name, as referencing the property with an expression would have the compiler throwing an error.
Please answer any or all of the questions below
It can be done with a manual ignore-rule, but this will reference the name as a string and not be future proof for any changes to the object.
I have not found any other alternatives than using the ignore-rule with the property name as string.
It is a problem as the concept of using
StrictMode
is to ensure rules will be updated if the object is changed in the future. With ignore a future removal of the old obsolete property would not fail and cleaning up the ignore rule would probably not be detected.No.
If the feature request is approved, would you be willing to submit a PR?
Yes