Forged uses a single marker attribute —Documentation Index
Fetch the complete documentation index at: https://mintlify.com/atulin/forged/llms.txt
Use this file to discover all available pages before exploring further.
[Fake] — to identify the classes and records that should have a strongly-typed faker generated for them. Placing this attribute on a type is all you need to do to opt in to compile-time code generation; there are no constructor parameters to configure and no properties to set.
Attribute declaration
FakeAttribute lives in the Forged.Core namespace. Its declaration is deliberately minimal:
AttributeTargets includes Struct, the Roslyn source generator currently processes only ClassDeclarationSyntax and RecordDeclarationSyntax nodes, so structs are accepted by the compiler but do not yet produce generated output.
Annotating a model
Add[Fake] to any class or record whose instances you want to generate. Mark the properties whose values are mandatory as required:
What happens at build time
Generator activation
The Roslyn incremental generator
ForgedGenerator activates whenever it finds a type decorated with Forged.Core.FakeAttribute.Property discovery
For each matching type, the generator inspects every member and keeps only
public properties that have a setter (SetMethod is not null). Each surviving property is recorded with its name, its fully-qualified type string, and whether it is required.Generated faker signature
For a model namedPerson, the generator emits the following skeleton:
| Property kind | Generated lambda type |
|---|---|
required | public required Func<Forge, IGenerator<T>> |
| optional | public Func<Forge, IGenerator<T>>? |
Properties without a setter, or properties that are not
public, are invisible to the generator and will not appear in the generated faker. This applies to computed properties, init-only properties that the generator cannot see, and any member with a non-public access modifier.