TypeFest.Net
1.0.2
dotnet add package TypeFest.Net --version 1.0.2
NuGet\Install-Package TypeFest.Net -Version 1.0.2
<PackageReference Include="TypeFest.Net" Version="1.0.2" />
paket add TypeFest.Net --version 1.0.2
#r "nuget: TypeFest.Net, 1.0.2"
// Install TypeFest.Net as a Cake Addin #addin nuget:?package=TypeFest.Net&version=1.0.2 // Install TypeFest.Net as a Cake Tool #tool nuget:?package=TypeFest.Net&version=1.0.2
TypeFest.Net
Ever wish C# had some of the utility types that TypeScript has? This library is the one for you.
Key Features
Pick
Just like you've come to love from TypeScript, this attribute allows you to pick properties off of another type to create another one. If the type of one of the properties in the source type changes so will they in the target type.
Example:
namespace Test;
public class Todo
{
public string Title { get; set; }
public int Description { get; set; }
public bool Completed { get; set; }
}
[Pick<Todo>("Title", "Completed")]
public partial class TodoPreview;
Under the hood, a type with the Title
and Completed
just like they are on Todo
. It will also generate a method with the following signature: public static TodoPreview From(Todo value)
for you so you can easily map from Todo
to TodoPreview
.
Omit
namespace Test;
public class Todo
{
public string Title { get; set; }
public int Description { get; set; }
public bool Completed { get; set; }
public DateTime CreatedAt { get; set; }
}
[Omit<Todo>("Description")]
public partial class TodoPreview;
Just like Pick
, this will create you a type but with all the defined properties removed. It will also create you a From
method for easily mapping between the two.
Pitfalls
Because this library makes use of C# source generators that means that the properties added to the type aren't accessible to other C# source generators. This is mainly a problem if you want to use these types with JSON source generation or configuration source generator. The properties won't be visible to them and they will not work they way you want. The best fix for this is some sort of framework to ensure some source generators work before others. But no such framework exists today, if you have ideas for one, please create an issue with it and link back to this issue and feel free to use this library as an example.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.2 | 62 | 1/23/2025 |
1.0.1 | 65 | 1/20/2025 |
1.0.0 | 47 | 1/20/2025 |
1.0.0-beta.1 | 33 | 1/20/2025 |