{"id":51256443,"url":"https://github.com/Atulin/Forged","last_synced_at":"2026-07-17T22:00:46.686Z","repository":{"id":363694618,"uuid":"1261688030","full_name":"Atulin/Forged","owner":"Atulin","description":"A fast, strict, and strongly-typed data generator (faker) for C# powered by Source Generators.  Forged allows you to declaratively define how your models should be faked, leveraging the C# compiler to enforce required properties, nullability, and type-safety.","archived":false,"fork":false,"pushed_at":"2026-07-03T06:36:45.000Z","size":204,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-07-04T11:36:20.458Z","etag":null,"topics":["dotnet","faker","generator","source-generator","source-generators"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Atulin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-07T02:55:54.000Z","updated_at":"2026-07-03T06:37:53.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/Atulin/Forged","commit_stats":null,"previous_names":["atulin/forged"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Atulin/Forged","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atulin%2FForged","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atulin%2FForged/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atulin%2FForged/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atulin%2FForged/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Atulin","download_url":"https://codeload.github.com/Atulin/Forged/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atulin%2FForged/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35597010,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-17T02:00:06.162Z","response_time":116,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","faker","generator","source-generator","source-generators"],"created_at":"2026-06-29T11:00:26.608Z","updated_at":"2026-07-17T22:00:46.680Z","avatar_url":"https://github.com/Atulin.png","language":"C#","funding_links":[],"categories":["Source Generators"],"sub_categories":["Testing"],"readme":"# Forged\n\n[![NuGet](https://img.shields.io/nuget/v/Atulin.Forged.svg)](https://www.nuget.org/packages/Atulin.Forged)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n[![.NET 10](https://img.shields.io/badge/.NET-10.0-purple.svg)](https://dotnet.microsoft.com/)\n\nA fast, strict, and strongly-typed data generator (faker) for C# powered by Source Generators.\n\nForged allows you to declaratively define how your models should be faked, leveraging the C# compiler to enforce required properties, nullability, and type-safety.\n\n## Features\n\n- 🚀 **Source Generated**: No reflection, fast at runtime, and fully trim/AOT compatible.\n- 🛡️ **Strict \u0026 Type-Safe**: Respects your class properties. If a property in your model is `required`, the faker will force you to provide a generator for it at compile time.\n- 🌊 **Fluent API**: A clean and readable fluent API for configuring generators and their modifiers.\n- 🎲 **Deterministic**: Pass a seeded `Random` instance to the faker to generate the exact same data every time.\n\n## Quick Start\n\n1. Add the package to your project.\n2. Decorate your model with `[Fake]`:\n\n```csharp\n[Fake]\npublic class Person\n{\n    public required Guid Id { get; set; }\n    public required string FirstName { get; set; }\n    public required string LastName { get; set; }\n    public List\u003cstring\u003e? MiddleNames { get; set; }\n    public bool IsActive { get; set; }\n    public DateTime? DateOfBirth { get; set; }\n}\n```\n\nor create a partial class with `[Faker\u003cT\u003e]` attribute:\n\n```csharp\n[Faker\u003cPerson\u003e]\npublic partial class PersonFaker;\n```\n\n3. The source generator will automatically create a `{ModelName}Faker` class for you. Configure it and generate data!\n\n```csharp\nusing Forged.Core.Generators; \nusing Forged.Core.Generators.Text; \n\n// The faker properties match your model's properties!\nvar faker = new PersonFaker\n{\n    Id = f =\u003e f.Text.Guid(GuidGenerator.Kind.V7),\n    FirstName = f =\u003e f.Text.Alphanumeric(10),\n    LastName = f =\u003e f.Text.Alphanumeric(10),\n    \n    // Non-required properties can be omitted, but you can still provide a generator:\n    MiddleNames = f =\u003e f.Text\n        .Alphanumeric(5)\n        .Collection(3)\n        .Refine(c =\u003e c.ToList()) // Map to List\u003cstring\u003e\n        .OrDefault(0.5f),        // 50% chance of being default (null)\n        \n    DateOfBirth = f =\u003e f.Temporal.Past().OrNull(0.2f), // 20% chance to be null\n    IsActive = f =\u003e f.Random.Pick(true, false)\n};\n\n// Generate a single item\nvar person = faker.Get();\n\n// Generate multiple items\nvar people = faker.Get(5);\n```\n\n\u003e [!INFO]\n\u003e When using the `Faker\u003cT\u003e` attribute, the generated faker will have the same name,\n\u003e not `{ModelName}Faker`.\n\n### Deterministic Generation\n\nIf you need reproducible results (e.g. in unit tests), you can provide a seeded `Random` instance to the faker:\n\n```csharp\nvar faker = new PersonFaker(new Random(12345)) \n{\n    // ...\n};\n```\n\n### Localization\n\nYou can optionally provide a `CultureInfo` instance to the faker, which will be utilized by modifiers that support localization:\n\n```csharp\nvar faker = new PersonFaker(locale: new CultureInfo(\"fr-FR\")) \n{\n    // ...\n};\n```\n\n### Referencing Other Properties\n\nIf you need to reference an already-generated value, you can use `.Memo()` and `.Func()` methods:\n\n```csharp\n// Unfortunate workaround, as `out var` does not work in object initializers.\nMemoValueGenerator\u003cstring\u003e first = null!;\nMemoValueGenerator\u003cstring\u003e last = null!;\n\nvar faker = new PersonFaker\n{\n    FirstName = f =\u003e f.Text.Pronounceable(5, 10).Memo(out first),\n    LastName = f =\u003e f.Text.Pronounceable(5, 10).Memo(out last),\n    MiddleNames = f =\u003e f.Basic.Func(() =\u003e $\"{first} {last}\"),\n}\n```\n\n## Available Generators\n\nThe `Forge` instance (`f` in the lambda expressions) provides access to built-in generators categorized by modules:\n\n### `Basic`\n- `.Literal(T value)` - Creates a generator that always returns the specified literal value.\n- `.Func(Func\u003cT\u003e func)` - Creates a generator that invokes the specified function.\n\n### `Random`\n- `Pick\u003cT\u003e(params T[] items)` - Pick a single random item from the given collection.\n- `Pick\u003cT\u003e(T[] items, int count)` - Pick an exact number of random items from the collection.\n- `Pick\u003cT\u003e(T[] items, int minCount, int maxCount)` - Pick a variable number of random items from the collection.\n- `Number\u003cT\u003e(T? min, T? max)` - Generate a random numeric value within the specified range (supports all numeric types).\n- `WeightedPick\u003cT\u003e(T[] items, float[] weights)` - Pick an item from the collection using specified weights for probability distribution.\n- `WeightedPick\u003cT\u003e((T item, float weight)[] items)` - Pick an item from an array of item-weight tuples.\n- `Dice(string expression, RoundingMode mode)` - Roll dice using a dice expression (e.g. `2d6+4`).\n\n### `Temporal`\n- `Between(DateTime? min, DateTime? max)` - Generate a random `DateTime` within the specified range.\n- `Past(DateTime? earliest)` - Generate a random `DateTime` in the past, with an optional earliest bound.\n- `Future(DateTime? latest)` - Generate a random `DateTime` in the future, with an optional latest bound.\n- `DateBetween(DateOnly? min, DateOnly? max)` - Generate a random `DateOnly` within the specified range.\n- `DateInPast(DateOnly? earliest)` - Generate a random `DateOnly` in the past, with an optional earliest bound.\n- `DateInFuture(DateOnly? latest)` - Generate a random `DateOnly` in the future, with an optional latest bound.\n- `TimeBetween(TimeOnly? min, TimeOnly? max)` - Generate a random `TimeOnly` within the specified range.\n\n### `Text`\n- `Alphanumeric(int length)` - Generate a random alphanumeric string of fixed length.\n- `Alphanumeric(int minLength, int maxLength)` - Generate a random alphanumeric string of variable length.\n- `Alpha(int length)` - Generate a random alphabetic string of fixed length.\n- `Alpha(int minLength, int maxLength)` - Generate a random alphabetic string of variable length.\n- `Pronounceable(int length)` - Generate a random pronounceable string (syllable-based) of fixed length.\n- `Pronounceable(int minLength, int maxLength)` - Generate a random pronounceable string of variable length.\n- `Lorem(int length, LoremIpsumGenerator.Options? options = null)` - Generate Lorem Ipsum text with a fixed number of words.\n- `Lorem(int minLength, int maxLength, LoremIpsumGenerator.Options? options = null)` - Generate Lorem Ipsum text with a variable number of words.\n- `Hex(int length)` - Generate a random hexadecimal string of fixed length.\n- `Hex(int minLength, int maxLength)` - Generate a random hexadecimal string of variable length.\n- `Guid(GuidGenerator.Kind kind)` - Generate a GUID of the specified kind (supports V4 and V7).\n- `Template(string template)` - Generate a string from a template with random placeholder replacements.\n\n### `Internet`\n- `Username(float prefixChance, float suffixChance, float leetChance)` - Generates a random username with configurable probability for including prefixes, suffixes, and leet-speak character substitutions.\n- `Domain(float ccSldChance = 0.0f)` - Generates a random domain name.\n- `Email(EmailKind kind = EmailKind.Random, IGenerator\u003cstring\u003e? provider = null)` - Generates a random email address.\n\n## Modifiers \u0026 Extensions\n\nAny `Generator\u003cT\u003e` can be customized and composed using fluent methods. These methods can be chained to create complex generation pipelines.\n\n### Core Modifiers (on `Generator\u003cT\u003e`)\n- `.Or(T other, float probability)` - Returns an alternative value with the specified probability (e.g., 0.2f = 20% chance).\n- `.OrDefault(float probability)` - Returns the default value for type T with the specified probability.\n- `.Refine\u003cTNew\u003e(Func\u003cT, TNew\u003e refiner)` - Transforms the generated value using the provided function.\n- `.Enumerable(int length)` - Generates an `IEnumerable\u003cT\u003e` with a fixed number of items.\n- `.Enumerable(int minLength, int maxLength)` - Generates an `IEnumerable\u003cT\u003e` with a variable number of items.\n- `.Array(int length)` - Generates a `T[]` array with a fixed number of items.\n- `.Array(int minLength, int maxLength)` - Generates a `T[]` array with a variable number of items.\n- `.List(int length)` - Generates a `List\u003cT\u003e` with a fixed number of items.\n- `.List(int minLength, int maxLength)` - Generates a `List\u003cT\u003e` with a variable number of items.\n- `.HashSet(int length)` - Generates a `HashSet\u003cT\u003e` with a fixed number of unique items.\n- `.HashSet(int minLength, int maxLength)` - Generates a `HashSet\u003cT\u003e` with a variable number of unique items.\n- `.Cast\u003cTOut\u003e()` - Casts the generated value to the specified type.\n\n### Nullable \u0026 Struct Extensions\n- `.OrNull(float probability)` - For struct generators, returns null with the specified probability.\n- `.Nullable()` - Converts a struct generator to a nullable struct generator.\n\n### Collection Conversion Extensions\n- `.AsList()` - Converts an `IEnumerable\u003cT\u003e` or `ICollection\u003cT\u003e` generator to a `List\u003cT\u003e` generator.\n- `.AsHashSet()` - Converts an `IEnumerable\u003cT\u003e` or `ICollection\u003cT\u003e` generator to a `HashSet\u003cT\u003e` generator.\n- `.AsDictionary\u003cT, TKey, TValue\u003e(keySelector, valueSelector)` - Converts an `IEnumerable\u003cT\u003e` generator to a `Dictionary\u003cTKey, TValue\u003e` using the provided selectors.\n\n### String-Specific Extensions\n- `.ToUpper()` - Converts generated strings to uppercase.\n- `.ToLower()` - Converts generated strings to lowercase.\n- `.Range(int start, int? end = null)` - Produces substrings within the specified range.\n- `.Replace(string oldValue, string newValue)` - Replaces all occurrences of a specified string with another string.\n- `.Replace(char oldValue, char newValue)` - Replaces all occurrences of a specified char with another char.\n- `.Replace(Regex regex, string newValue)` - Replaces substrings matching a regular expression with another string.\n- `.ToTitleCase(CultureInfo? cultureInfo)` - Converts generated strings to title case using the specified culture.\n- `.Capitalize(CultureInfo? cultureInfo)` - Capitalizes the first character of generated strings.\n- `.Sentencify(int sentenceLength, CultureInfo? cultureInfo)` - Formats strings as proper sentences with a fixed word count.\n- `.Sentencify(int minSentenceLength, int maxSentenceLength, CultureInfo? cultureInfo)` - Formats strings as proper sentences with a variable word count.\n\n### Temporal-Specific Extensions (DateTime)\n- `.ToUtc()` - Converts generated DateTime values to UTC.\n- `.ToLocal()` - Converts generated DateTime values to local time.\n- `.ToDateOnly()` - Extracts the date component from DateTime values, producing DateOnly.\n- `.ToTimeOnly()` - Extracts the time component from DateTime values, producing TimeOnly.\n- `.TruncateToDate()` - Truncates DateTime values to date precision (sets time to midnight).\n\n### Formatting Extensions\n- `.ToString()` - Converts generated values to their string representation.\n- `.ToString(string format, CultureInfo? cultureInfo)` - Converts generated values to formatted strings using the specified format and culture (for types implementing `ISpanFormattable`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAtulin%2FForged","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAtulin%2FForged","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAtulin%2FForged/lists"}