Facet 1.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Facet --version 1.3.0
                    
NuGet\Install-Package Facet -Version 1.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Facet" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Facet" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Facet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Facet --version 1.3.0
                    
#r "nuget: Facet, 1.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Facet@1.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Facet&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Facet&version=1.3.0
                    
Install as a Cake Tool

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 C# source generator that produces slim DTOs, typed projections, and API-bound view models — directly from your domain models.

Zero runtime cost, no boilerplate.


  • ✳️ Generate partial classes or records based on existing types
  • 🔧 Exclude fields/properties you don’t need, or add new ones
  • 📫 Include public fields (opt-in)
  • 🔨 Support custom mapping logic
  • 🔗 Auto-generate constructors to initialize target from source
  • 🔩 Works with records, classes, readonly, and init-only members

Quick Start

1. Install

dotnet add package Facet

2. Create your facet

Define a partial class, attach the Facet attribute and you're done.

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

3. Usage

var person = new Person
{
    Name = "Tim",
    Email = "hidden@example.com",
    Age = 33,
    RawId = Guid.NewGuid()
};

var dto = new PersonDto(person);

Complex mapping support

If you want to map properties with custom logic, you can use the Facet.Mapping package.

1. Install the mapping package

dotnet add package Facet.Mapping

2. Define your models

Source model:

public class User
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime Registered { get; set; }
}

Target facet:

[Facet(
    typeof(User),
    exclude: new[] { ... }, //optional
    Configuration = typeof(UserMapConfig))]
public partial class UserDto
{
    public string FullName { get; set; }
    public string RegisteredText { get; set; }
}

3. Create and use map configuration

Mapping configuration from source to your facet:

public class UserMappConfig : IFacetMapConfiguration<User, UserDto>
{
    public static void Map(User source, UserDto target)
    {
        target.FullName = $"{source.FirstName} {source.LastName}";
        target.RegisteredText = source.Registered.ToString("yyyy-MM-dd");
    }
}

Now you can just create a DTO instance, and the source object will be mapped accordingly.

var user = new User
{
  FirstName = "Tim",
  LastName = "Maes",
  Registered = new DateTime(2020, 1, 15)
}

var dto = new UserDto(user);

Console.WriteLine(dto.FullName);        // Tim Maes
Console.WriteLine(dto.RegisteredText); // 2020-01-15

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Facet:

Package Downloads
Facet.Extensions

Provider-agnostic extension methods for Facet.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.6.1 38 9/10/2025
2.6.0 53 9/9/2025
2.5.0 280 9/4/2025
2.4.8 196 9/3/2025
2.4.7 242 9/1/2025
2.4.6 132 9/1/2025
2.4.5 202 8/30/2025
2.4.4 416 8/27/2025
2.4.3 189 8/27/2025
2.4.2 181 8/27/2025
2.4.1 215 8/26/2025
2.4.0 204 8/26/2025
2.3.0 1,545 8/20/2025
2.2.0 159 8/20/2025
2.1.0 267 8/18/2025
2.0.1 764 8/5/2025
2.0.0 155 8/4/2025
1.9.3 197 7/4/2025
1.9.1 156 7/3/2025
1.9.0 154 7/3/2025
1.8.0 253 6/4/2025
1.7.0 211 5/6/2025
1.6.0 180 4/27/2025
1.5.0 219 4/26/2025
1.4.0 144 4/25/2025
1.3.0 171 4/24/2025
1.2.0 176 4/24/2025
1.1.1 176 4/23/2025
1.1.0 181 4/23/2025
1.0.2 376 4/23/2025
1.0.1 191 4/23/2025
1.0.0 190 4/23/2025
0.1.0 183 4/22/2025