Downcastly 1.0.3

dotnet add package Downcastly --version 1.0.3
                    
NuGet\Install-Package Downcastly -Version 1.0.3
                    
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="Downcastly" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Downcastly" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Downcastly" />
                    
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 Downcastly --version 1.0.3
                    
#r "nuget: Downcastly, 1.0.3"
                    
#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 Downcastly@1.0.3
                    
#: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=Downcastly&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Downcastly&version=1.0.3
                    
Install as a Cake Tool

Downcastly - A C# Library for Safe Downcasting with Compile-Time Type Checking

Downcastly is a C# library that provides a safe and efficient way to downcast objects with compile-time type checking. It automatically generates downcasting constructors for your classes to copy all the properties from the base class to the derived class, ensuring type safety and reducing boilerplate code.

usage example

    public record ParentRecord
    {
        public int Id { get; init; }

        public string Name { get; init; }
    }

    [Downcast]
    public partial record ChildRecord : ParentRecord
    {
        public string Status { get; init; }
    }

    public class Program
    {
        public static void Main()
        {
            ParentRecord parent = new()
            {
                Id = 1,
                Name = "Parent"
            };

            // Safe downcasting using Downcastly
            ChildRecord child = new ChildRecord(parent) { Status = "active" };
            Console.WriteLine($"Id: {child.Id}, Name: {child.Name}, Status: {child.Status}");
        }
    }

installation

dotnet add package Downcastly

usefull tips

Add following line to your PropertyGroup of your .csproj file so you can see generated files in your obj folder:

<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\Generated</CompilerGeneratedFilesOutputPath>

why not to use AutoMapper, Mapster or similar libraries instead?

Those libraries are great for mapping between different types, but with that strenth comes complexity. It's easy to start using them not only for downcasting but also for other mapping scenarios, which can lead to overcomplication of your codebase, complicated configurations, unnecessary abstractions, and debudding overhead. We all know that using mappers is very easy until it suddenly becomes really hard.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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.3 371 1/3/2026
1.0.2 245 12/29/2025
1.0.1 253 12/27/2025