Facet 1.1.0
See the version list below for details.
dotnet add package Facet --version 1.1.0
NuGet\Install-Package Facet -Version 1.1.0
<PackageReference Include="Facet" Version="1.1.0" />
<PackageVersion Include="Facet" Version="1.1.0" />
<PackageReference Include="Facet" />
paket add Facet --version 1.1.0
#r "nuget: Facet, 1.1.0"
#:package Facet@1.1.0
#addin nuget:?package=Facet&version=1.1.0
#tool nuget:?package=Facet&version=1.1.0
This is a new project, any help, feedback and contributions are highy appreciated.
Facet
"One part of a subject, situation, etc. that has many parts."
Facet is a compile-time source generator that creates partial classes from existing types — by copying only the members you want.
Exclude properties, include public fields, add your own members, or generate a constructor — all with a single [Facet]
attribute.
Use Facet to build lightweight DTOs, API shapes, or UI-bound view models without writing boilerplate or mapping code.
No base classes. No mapppings. No reflection. No runtime cost.
Features
- ✅ Add or exclude properties
- ✅ Include public fields (optional)
- ✅ Generate constructors that copy from the source type
- ✅ No base class or interface required
- ✅ No runtime reflection — compile-time only
- ✅ Works with or without namespaces
- ✅ Don't worry about usings
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; }
}
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.
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[] { nameof(User.FirstName), nameof(User.LastName), nameof(User.Registered) },
Configuration = typeof(UserMapper))]
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 UserMapper : 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");
}
}
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 | Versions 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. |
-
.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.7.0 | 0 | 9/12/2025 |
2.6.2 | 8 | 9/12/2025 |
2.6.1 | 87 | 9/10/2025 |
2.6.0 | 94 | 9/9/2025 |
2.5.0 | 285 | 9/4/2025 |
2.4.8 | 201 | 9/3/2025 |
2.4.7 | 243 | 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,546 | 8/20/2025 |
2.2.0 | 159 | 8/20/2025 |
2.1.0 | 267 | 8/18/2025 |
2.0.1 | 766 | 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 | 212 | 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 | 191 | 4/23/2025 |
0.1.0 | 183 | 4/22/2025 |