DeepExtensions 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DeepExtensions --version 0.2.0
                    
NuGet\Install-Package DeepExtensions -Version 0.2.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="DeepExtensions" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DeepExtensions" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="DeepExtensions" />
                    
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 DeepExtensions --version 0.2.0
                    
#r "nuget: DeepExtensions, 0.2.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 DeepExtensions@0.2.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=DeepExtensions&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=DeepExtensions&version=0.2.0
                    
Install as a Cake Tool

Deep Extentions

The Deep Extentions are a collection of three Deep features based on Source Generation.

Features

  • Roslyn Code Generator
  • AOT-compatible
  • Trimmable
  • CommunityToolkit.Mvvm compatible.
  • WPF, WinUI, and Avalonia compatible.

Installation

Nuget package

DeepCopy

Generates code for deep copy.

Attributes

[DeepCopy]

The [DeepCopy] attribute only needs to be placed on the root element; it signals that a deep copy should be generated recursively for this class, all its base classes, and all its propertiy classes.

[DeepCopyIgnore]

All properties with [DeepCopyIgnore] will be ignored.

Example

namespace Demo.Models;

[DeepCopy]
public partial class DemoModel
{
    public string Name { get; set; } = "Peter";

    public SubModel Sub { get; set; } = new SubModel();

    [DeepCopyIgnore]
    public int Num { get; set; } = 45;
}

// Generated

partial class DemoModel : IDeepCopy<DemoModel>
{
    public DemoModel DeepCopy()
    {
        return DemoModel()
        {    
            Name = this.Name;
            Sub = this.Sub?.DeepCopy()
        }
    }
}

DeepEqual

Generates code for deep equal.

[DeepEqual]

The [DeepEqual] attribute only needs to be placed on the root element; it signals that a deep equal should be generated recursively for this class, all its base classes, and all its propertiy classes.

[DeepEqualIgnore]

All properties with [DeepEqualIgnore] will be ignored.

Example

namespace Demo.Models;

[DeepEqual]
public partial class DemoModel
{
    public string Name { get; set; } = "Peter";

    public SubModel Sub { get; set; } = new SubModel();

    [DeepEqualIgnore]
    public int Num { get; set; } = 45;
}

// Generated

partial class DemoModel : IDeepEqual<DemoModel>
{
    public bool DeepEqual(DemoModel? value)
    {
        if (value is null) return false;
        return
            Name == value.Name &&
            (Sub is null && value.Sub is null) || (Sun is not null && Sub.DeepEqual(value.Sub);
    }
}

DeepMap

Mapping between Model and ViewModel trees

  • Custom converters

Examples

Simple Types

Synchronizing properties with simple data types between the Model and the ViewModel.

Model
namespace Demo.Models;

public class DemoModel
{
    public string Name { get; set; } = "Peter";
}
ViewModel
using CommunityToolkit.Mvvm.ComponentModel;
using MvvmToolbox.ComponentModel;
using ObservableModelGeneratorUnitTests.Models;

namespace Demo.ViewModels;

[ObservableModelObject(typeof(DemoModel))]
public partial class DemoViewModel : ObservableObject
{
    [ObservableProperty]
    [ObservableModelProperty]
    public partial string Name { get; set; }
}

List of Simple Types

Synchronizing properties with a list of simple data types between the Model and the ViewModel.

Model
namespace Demo.Models;

public class DemoModel
{
    public List<string> Names { get; set; } = [ "Peter", "Paul", "Mary"];
}
ViewModel
using CommunityToolkit.Mvvm.ComponentModel;
using MvvmToolbox.ComponentModel;
using ObservableModelGeneratorUnitTests.Models;

namespace Demo.ViewModels;

[ObservableModelObject(typeof(DemoModel))]
public partial class DemoViewModel : ObservableObject
{
    // no partial, no set, no nullable, and no [ObservableProperty]
    [ObservableModelProperty]
    public ObservableCollection<string> Names { get; }
}

Different Names

Synchronizing properties with different names between Model and ViewModel.

Model
namespace Demo.Models;

public class DemoModel
{
    public string Name { get; set; } = "Peter";
}
ViewModel
using CommunityToolkit.Mvvm.ComponentModel;
using MvvmToolbox.ComponentModel;
using ObservableModelGeneratorUnitTests.Models;

namespace Demo.ViewModels;

[ObservableModelObject(typeof(DemoModel))]
public partial class DemoViewModel : ObservableObject
{
    [ObservableProperty]
    [ObservableModelProperty(nameof(DemoModel.Name))]
    public partial string FirstName { get; set; }
}

Children

Synchronizing properties with children between Model and ViewModel.

Model
namespace Demo.Models;

public class RootModel
{
    public LeafModel? Leaf { get; set; } = new LeafModel();
}

public class LeafModel
{
    public string Name { get; set; } = "Peter";
}
ViewModel
using CommunityToolkit.Mvvm.ComponentModel;
using MvvmToolbox.ComponentModel;
using ObservableModelGeneratorUnitTests.Models;

namespace Demo.ViewModels;

[ObservableModelObject(typeof(RootModel))]
public partial class RootViewModel : ObservableObject
{
    [ObservableProperty]
    [ObservableModelProperty]
    public partial LeafViewModel? Leaf { get; set; }
}

[ObservableModelObject(typeof(LeafModel))]
public partial class LeafViewModel : ObservableObject
{
    [ObservableProperty]
    [ObservableModelProperty]
    public partial string Name { get; set; }
}

List of Children

Synchronizing properties with a list of children between Model and ViewModel.

Model
namespace Demo.Models;

public class RootModel
{
    public List<LeafModel> Leafs { get; set; } = [new LeafModel(), new LeafModel()];
}

public class LeafModel
{
    public string Name { get; set; } = "Peter";
}
ViewModel
using CommunityToolkit.Mvvm.ComponentModel;
using MvvmToolbox.ComponentModel;
using ObservableModelGeneratorUnitTests.Models;

namespace Demo.ViewModels;

[ObservableModelObject(typeof(RootModel))]
public partial class RootViewModel : ObservableObject
{
    // no partial, no set, no nullable, and no [ObservableProperty]
    [ObservableModelProperty]
    public ObservableCollection<LeafViewModel> Leafs { get; }
}

[ObservableModelObject(typeof(LeafModel))]
public partial class LeafViewModel : ObservableObject
{
    [ObservableProperty]
    [ObservableModelProperty]
    public partial string Name { get; set; }
}

Converter Functions

Synchronizing properties with converters between the Model and the ViewModel. The converters can also be applied to lists and "list to simpleType" mappings.

Model
namespace Demo.Models;

public class DemoModel
{
    public int Num { get; set; } = 25;
}
ViewModel
using CommunityToolkit.Mvvm.ComponentModel;
using MvvmToolbox.ComponentModel;
using ObservableModelGeneratorUnitTests.Models;

namespace Demo.ViewModels;

[ObservableModelObject(typeof(DemoModel))]
public partial class DemoViewModel : ObservableObject
{
    [ObservableProperty]
    [ObservableModelProperty(Converter = "NumConvert")]
    public partial string Num { get; set; }

    private string GetNumConvert(int val) => val.ToString();
    private int SetNumConvert(string val) => int.Parse(val);
}

Converter Interface

Synchronizing properties with converters between the Model and the ViewModel. The converters can also be applied to lists and "list to simpleType" mappings.

Model
namespace Demo.Models;

public class DemoModel
{
    public int Num { get; set; } = 25;
}
ViewModel
using CommunityToolkit.Mvvm.ComponentModel;
using MvvmToolbox.ComponentModel;
using ObservableModelGeneratorUnitTests.Models;

namespace Demo.ViewModels;

[ObservableModelObject(typeof(DemoModel))]
public partial class DemoViewModel : ObservableObject
{
    [ObservableProperty]
    [ObservableModelProperty(ConverterType = typeof(IntToStringConverter))]
    public partial string Num { get; set; }

    private string GetNumConvert(int val) => val.ToString();
    private int SetNumConvert(string val) => int.Parse(val);

    public class IntToStringConverter : IPropertyConverter
    {
        public object Convert(object value) => value?.ToString()!;
        public object ConvertBack(object value) => (value is string input && int.TryParse(input, out int result)) ? result : null!;
    }
}
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has 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
0.7.0 70 11/27/2026
0.6.0 67 11/26/2026
0.5.0 65 11/22/2026
0.4.0 69 11/17/2026
0.3.0 70 11/9/2026
0.2.0 70 11/8/2026
0.1.0 70 11/6/2026

Creation