Strict mode problem with obsolete property
- Dominant language
- C#
- Stars
- 9.7k
- Forks
- 538
- PR merge metrics
- No merged PRs in 30d
Description
### 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:
```
Bogus.ValidationException : Validation was called to ensure all properties / fields have rules.
There are missing rules for Faker 'MyObject'.
=========== Missing Rules ===========
SomeOldProperty
```
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](https://github.com/bchavez/Bogus/issues/13).
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:
```csharp
public string TheNewProperty { get; set; }
[Obsolete("Use property 'TheNewProperty' instead", true)]
public string SomeOldProperty { get; set; }
```
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:
```
var myObjectFaker = new Faker().StrictMode(true)
.RuleFor(p => p.TheNewProperty, f => f.Address.StreetName());
```
One way to work around this is using the `Ignore` statement
```
var myObjectFaker = new Faker().StrictMode(true)
.RuleFor(p => p.TheNewProperty, f => f.Address.StreetName())
.Ignore("SomeOldProperty"); // Obsolete property, was replaced by 'TheNewProperty'
```
This 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
* Is the feature something that currently cannot be done?
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.
* What alternatives have you considered?
I have not found any other alternatives than using the ignore-rule with the property name as string.
* Is this feature request any issues or current problems?
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.
* Has the feature been requested in the past?
No.
**If the feature request is approved, would you be willing to submit a PR?**
Yes
Contributor guide
Research direction
Start by locating the StrictMode validation and the existing readonly-property handling, then inspect the related validation tests. Add a regression test for a property marked [Obsolete(..., true)] and confirm that strict mode no longer reports it as missing while still enforcing rules for current properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100