Facet.Extensions
1.5.0
See the version list below for details.
dotnet add package Facet.Extensions --version 1.5.0
NuGet\Install-Package Facet.Extensions -Version 1.5.0
<PackageReference Include="Facet.Extensions" Version="1.5.0" />
<PackageVersion Include="Facet.Extensions" Version="1.5.0" />
<PackageReference Include="Facet.Extensions" />
paket add Facet.Extensions --version 1.5.0
#r "nuget: Facet.Extensions, 1.5.0"
#addin nuget:?package=Facet.Extensions&version=1.5.0
#tool nuget:?package=Facet.Extensions&version=1.5.0
This is a new project, any help, feedback and contributions are highy appreciated.
Facet
"One part of a subject, situation, object that has many parts."
Facet is a source generator that instantly scaffolds DTOs, typed LINQ projections, and ViewModels without any runtime overhead.
- ✅ Zero runtime cost: all mapping logic happens at compile time
- ✅ Boilerplate-free: write only your domain and facet definitions
- ✅ Configurable: exclude members, include fields, add custom mapping
- ✅ Queryable: produce
Expression<Func<TSource,TTarget>>
for EF Core and other LINQ providers
Feature | Description |
---|---|
Partial classes & records | Generate partial class or record from your types |
Exclude members | Omit unwanted properties or fields via attribute parameters |
Include public fields | Opt‑in support for mapping public fields |
Custom mapping logic | Hook into IFacetMapConfiguration<TSource, TTarget> with static Map() |
Constructor & projection | Auto-generate ctor and/or Expression<Func<…, …>> for LINQ providers |
Records, classes, readonly, init-only | Works with all member kinds |
Quick Start
1. Install
dotnet add package Facet
2. Create your facet
Define a partial class
, attach the Facet
attribute and you're done. By default you get:
- A constructor
(TSource source)
- A static
Expression<Func<TSource,TTarget>>
Projection
using Facet;
public class Person
{
public string Name { get; set; }
public string Email { get; set; }
public int Age { get; set; }
public Guid RawId;
}
// Generate class that can be mapped from source model
[Facet(typeof(Person), GenerateConstructor = true)]
public partial class PersonDto { }
// Generate class while adding and removing properties
// You can pass an array of properties to exclude
[Facet(typeof(Person), exclude: nameof(Person.Email)]
public partial class PersonWithNote
{
public string Note { get; set; }
}
[Facet(typeof(Person), Kind = FacetKind.Record]
public partial record PersonRecord
{
// ..
}
The PersonDto
will have a constructor that maps the source type properties.
PersonWithNote
is generated and will not have the Email property, but will have the Note property.
PersoneRecord
is generated as a record
You can map source to target:
var person = new Person { Name = "Tim", Email = "x@x.com", Age = 33, RawId = Guid.NewGuid() };
// 3.1 Constructor mapping
var dto = new PersonDto(person);
Ergonomic mapping helpers (optional)
If you install Facet.Extensions, you get extension methods:
using Facet.Extensions;
// Single-object ctor mapping
var dto = person.ToFacet<Person,PersonDto>();
// In-memory list mapping
var dtos = people.SelectFacets<Person,PersonDto>().ToList();
// Deferred projection
var dtos = dbContext.People
.SelectFacet<Person,PersonDto>()
.ToList();
And if you install Facet.EntityFrameworkCore (on .NET 6+):
using Facet.EntityFrameworkCore;
// Async bulk projection
var dtosAsync = await dbContext.People
.SelectFacet<Person,PersonDto>()
.ToFacetsAsync(cancellationToken);
// Async first-or-default
var first = await dbContext.People
.FirstFacetAsync<Person,PersonDto>(cancellationToken);
Advanced mapping
Custom map configuration
Install the package:
dotnet add package Facet.Mapping
Define a mapping config
using Facet;
public class UserMapConfig : IFacetMapConfiguration<User,UserDto>
{
public static void Map(User src, UserDto dst)
{
dst.FullName = $"{src.FirstName} {src.LastName}";
dst.RegisteredText = src.Registered.ToString("yyyy-MM-dd");
}
}
Apply
[Facet(
typeof(User),
exclude: new[] { "Password" },
Configuration = typeof(UserMapConfig))]
public partial class UserDto { public string FullName { get; set; } }
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. |
-
net8.0
- Facet (>= 1.6.0)
- Microsoft.EntityFrameworkCore (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.