ImplementationScanner 1.0.1
See the version list below for details.
dotnet add package ImplementationScanner --version 1.0.1
NuGet\Install-Package ImplementationScanner -Version 1.0.1
<PackageReference Include="ImplementationScanner" Version="1.0.1" />
<PackageVersion Include="ImplementationScanner" Version="1.0.1" />
<PackageReference Include="ImplementationScanner" />
paket add ImplementationScanner --version 1.0.1
#r "nuget: ImplementationScanner, 1.0.1"
#:package ImplementationScanner@1.0.1
#addin nuget:?package=ImplementationScanner&version=1.0.1
#tool nuget:?package=ImplementationScanner&version=1.0.1
ImplementationScanner
A .NET library that scans assemblies for types implementing a specified base type, creates instances using reflection, and populates them with realistic fake data using the Bogus library.
Features
- Assembly Scanning: Automatically discovers all types that implement or inherit from a specified base type
- Instance Creation: Creates instances using reflection without invoking constructors
- Fake Data Population: Populates object properties with realistic fake data using Bogus
- JSON Serialization: Generates JSON representations of created instances
- Custom Filtering: Supports custom type filters for fine-grained control over which types to include
- Generic Design: Works with any base type, class, or interface
Installation
Prerequisites
- .NET 8.0 or higher
Building from Source
Clone the repository:
git clone https://github.com/Rad1c/ImplementationScanner.git cd ImplementationScannerBuild the solution:
dotnet buildRun the demo:
dotnet run --project EventLibraryGenerator
Usage
Basic Example
using EventLibraryGenerator;
using EventLibraryGenerator.Demo;
// Generate instances of all types that implement BaseEvent
var events = ImplementationScanner<BaseEvent>.GenerateEvents();
Console.WriteLine($"Generated {events.Count} events.");
// Generate JSON representation
string json = ImplementationScanner<BaseEvent>.GenerateEventsJsonString();
Console.WriteLine(json);
Custom Type Filtering
// Filter to only include types whose names end with "Event"
ImplementationScanner<BaseEvent>.SetTypeFilter(t =>
typeof(BaseEvent).IsAssignableFrom(t) &&
t.Name.EndsWith("Event") &&
!t.IsAbstract);
var filteredEvents = ImplementationScanner<BaseEvent>.GenerateEvents();
Working with System Types
using System.Transactions;
// Works with built-in .NET types too
var transactions = ImplementationScanner<Transaction>.GenerateEvents();
Console.WriteLine($"Generated {transactions.Count} transactions.");
API Reference
ImplementationScanner<TBase> Class
Methods
GenerateEvents()
Returns a list of instances of all types that implement TBase.
Returns: List<TBase> - List of populated instances
GenerateEventsJsonString()
Generates a JSON string representation of all instances.
Returns: string - JSON array containing all instances
SetTypeFilter(Func<Type, bool> filter)
Sets a custom filter to control which types are included.
Parameters:
filter- A function that takes aTypeand returnsbool
CreateAndPopulate(Type eventType, Faker faker)
Creates and populates a single instance of the specified type.
Parameters:
eventType- The type to instantiatefaker- Bogus faker instance for generating fake data
Returns: object? - Populated instance or null if creation failed
Supported Data Types
The library automatically generates appropriate fake data for common .NET types:
string- Random wordsint- Random integers (1-1000)decimal- Random decimals (10-1000)Guid- New GUIDsDateTime- Random dates- Complex objects - Recursively populated
- Collections - Populated with fake items
Example Domain Model
namespace EventLibraryGenerator.Demo;
public abstract class BaseEvent
{
// Base event class
}
public class UserCreatedEvent : BaseEvent
{
public string Username { get; set; }
public string Email { get; set; }
}
Output Example
Running the demo application produces output like:
Generated 1 events.
[{
"Username": "sed",
"Email": "et"
}]
Generated 1 filtered events.
Generated 3 transactions.
How It Works
- Assembly Scanning: Uses reflection to scan all loaded assemblies for types
- Type Filtering: Applies built-in and custom filters to select relevant types
- Instance Creation: Uses
FormatterServices.GetUninitializedObject()to create instances without calling constructors - Property Population: Iterates through public properties and sets them with fake data
- Circular Reference Handling: Tracks visited types to prevent infinite recursion
- JSON Serialization: Uses
System.Text.Jsonfor JSON output
Dependencies
- Bogus (v35.6.3) - For generating fake data
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Bogus (>= 35.6.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.