bchavez / bchavez/Bogus

Parse with extension

Open
#407 2 comments 0 reactions 0 assignees View on GitHub
enhancement question
Dominant language
C#
Stars
9.7k
Forks
538
PR merge metrics
No merged PRs in 30d

Description

Hello and thanks for the product

### Version Information
| Software | Version(s) |
| ------------------------| ---------- |
| Bogus NuGet Package | 34.0.1 |
| .NET Core? | 5.0 |
| .NET Full Framework? | N/A |
| Windows OS? | N/A |
| Linux OS? | Ubuntu 20.04.3 LTS |
| Visual Studio? | VSCode 1.63.2 |

### What locale are you using with Bogus?

fr

### What's the problem?

I created an extension method for Bogus following the example here: https://github.com/bchavez/Bogus/blob/master/Examples/ExtendingBogus/ExtensionsForAddress.cs
I'd like to parse an expression that uses this extension:

```csharp
faker.Parse("{{address.downtownTorontoPostalCode}}");
```
Is it something doable? Or is there any other solution to extend a dataset that would allow me to use the parser?

Looking at the code, it does not seem to be possible using extension methods because of this: https://github.com/bchavez/Bogus/blob/59985ee11fb2a34b89d940d5da8b34617f6f9f6f/Source/Bogus/Tokenizer.cs#L92
DeclaringType cannot be a dataset from Bogus

Contributor guide

Open the contributing guide

Research direction

Start with Tokenizer.cs at line 92 and the linked ExtensionsForAddress.cs example to understand how Parse handles the requested extension expression. Trace the limitation around DeclaringType, then determine whether a supported extension approach can be defined; done means the requested Parse usage or an alternative documented approach is clearly established.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.