SourceCrafter.Bindings 1.24.310.349

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

Mapper.Generator: Source generator for conversion operators and static methods

deploy status

⚙️ Supports

  • Assembly global mappings
  • Map inherited members
  • Custom static mapper methods
  • Property level mapping
  • Ignore mapping behaviors (Levels: assembly, class, property)
  • Easy to use variants
    • Extension method (Generated through assembly attributes)
        var typeA = typeB.ToTypeA();
      

🏛️ Scenarios

Assembly level

Attribute specification ([assembly: Map<TTarget, TSource>])
[assembly: Map<WindowsUser,WindowsIdentity>(nameof(GlobalMappers.MapToWindowsIdentity))]
Generated content (class <namespace>.GlobalMappers)
namespace Test;

public static partial class GlobalMappers {
    
    public static Test.WindowsUser ToWindowsUser(this System.Security.Principal.WindowsIdentity from)
    {
        return new Test.WindowsUser {
		Name = from.Name,
		IsAuthenticated = from.IsAuthenticated
        };
    }
    public static System.Security.Principal.WindowsIdentity ToWindowsIdentity(this Test.WindowsUser from)
    {
        return Test.GlobalMappers.MapToWindowsIdentity(from);
    }
}

Having a project file for a GlobalMappers partial class

public static partial class GlobalMappers
{
    public static WindowsIdentity MapToWindowsIdentity(this WindowsUser from) 
    {
        return new(from.Name);
    }
}

Class level


public partial class Role
{
    public int Id { get; set; }
    public string Name { get; set; } = null!;

    public static explicit operator Role((int id, string name) role) => new() { Id = role.id, Name = role.name };
    public static explicit operator (int id, string name)(Role role) => (role.Id, role.Name);
}

public partial class User
{
    public int Count { get; set; }

}

public partial class UserBase
{

    internal string FullName
    {
        get => $"{LastName?.Trim()}, {FirstName?.Trim()}";
        set => (FirstName, LastName) = value?.Split(", ") switch
        {
            [{ } lastName, { } firstName] => (firstName.Trim(), lastName.Trim()),
            [{ } firstName] => (firstName, null!),
            _ => (null!, null!)
        };
    }
    public string FirstName { get; set; } = null!;
    public string? LastName { get; set; }
    public int Age { get; set; }
}


[Map<UserDto>]
public partial class User : UserBase
{
    [Ignore(Ignore.OnSource)]
    public string? Unwanted { get; set; }
    public DateTime DateOfBirth { get; set; }
    [Map(nameof(UserDto.TotalAmount), Ignore.OnTarget)]
    public double Balance { get; set; }
    public List<Role> Roles { get; set; } = new();
    public Role? MainRole { get; set; }
}

public partial class UserDto
{
    public string FullName { get; set; } = null!;
    public int Count { get; set; }
    public int Age { get; set; }
    public string? Unwanted { get; set; }
    public DateTime DateOfBirth { get; set; }
    public (int, string)[] Roles { get; set; } = Array.Empty<(int, string)>();
    public (int, string) MainRole { get; set; } = default;
    public decimal TotalAmount { get; set; }
}

[Map<WindowsIdentity>(nameof(GlobalMappers.MapToWindowsIdentity))]
public partial class WindowsUser
{
    public string Name { get; set; } = null!;
    public bool IsAuthenticated { get; set; }
}

[Map<UserDto>] public partial class User produces:
namespace Test;

public static partial class MapperExtensions
{    
    public static Test.User ToUser(Test.UserDto from)
    {
        return new Test.User {
	        FullName = from.FullName,
	        Age = from.Age,
	        Count = from.Count,
	        Unwanted = from.Unwanted,
	        DateOfBirth = from.DateOfBirth,
	        Roles = ToListOfRole(from.Roles),
	        MainRole = ToRole(from.MainRole)
        };
    }
    public static Test.User ToUserDto(Test.User from)
    {
        return new Test.UserDto {
	        FullName = from.FullName,
	        Age = from.Age,
	        Count = from.Count,
	        DateOfBirth = from.DateOfBirth,
	        TotalAmount = (decimal)from.Balance,
	        Roles = ToArrayOfTupleOfStringString(from.Roles),
	        MainRole = ToTupleOfStringString(from.MainRole)
        };
    }
}
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.

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.24.310.349 112 11/5/2024
1.24.305.73 112 10/31/2024
1.24.305.70 109 10/31/2024
1.24.305.69 110 10/31/2024
1.24.305.67 100 10/31/2024
1.24.304.465 106 10/30/2024
1.24.304.362 108 10/30/2024
1.24.304.205 113 10/30/2024
1.24.303.30 108 10/29/2024
1.24.303.20 97 10/29/2024
1.24.301.422 111 10/27/2024
1.24.301.420 102 10/27/2024
1.24.301.400 105 10/27/2024
1.24.301.385 105 10/27/2024
1.24.301.383 110 10/27/2024
1.24.301.341 127 10/27/2024
1.24.301.340 102 10/27/2024
1.24.301.331 99 10/27/2024
1.24.301.324 102 10/27/2024
1.24.301.323 101 10/27/2024
1.24.301.310 115 10/27/2024
1.24.301.308 101 10/27/2024
1.24.301.306 108 10/27/2024
1.24.301.92 111 10/27/2024
1.24.299.54 106 10/25/2024
1.24.298.55 109 10/24/2024
1.24.298.2 110 10/24/2024
1.24.200.88 122 7/18/2024
1.24.158.55 127 6/6/2024
1.24.158.53 123 6/6/2024
1.24.158.48 121 6/6/2024
1.24.145.16 136 5/24/2024
1.24.143.87 138 5/22/2024
1.24.140.54 124 5/19/2024
1.24.82.88 158 3/22/2024
1.24.72.77 158 3/12/2024
1.24.72.56 143 3/12/2024
1.24.70.72 165 3/10/2024
1.24.70.59 159 3/10/2024
1.24.69.90 155 3/9/2024
1.24.69.77 155 3/9/2024
1.24.69.62 151 3/9/2024