TypeUtilities 0.0.1-alpha2

This is a prerelease version of TypeUtilities.
There is a newer version of this package available.
See the version list below for details.
dotnet add package TypeUtilities --version 0.0.1-alpha2                
NuGet\Install-Package TypeUtilities -Version 0.0.1-alpha2                
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="TypeUtilities" Version="0.0.1-alpha2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TypeUtilities --version 0.0.1-alpha2                
#r "nuget: TypeUtilities, 0.0.1-alpha2"                
#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.
// Install TypeUtilities as a Cake Addin
#addin nuget:?package=TypeUtilities&version=0.0.1-alpha2&prerelease

// Install TypeUtilities as a Cake Tool
#tool nuget:?package=TypeUtilities&version=0.0.1-alpha2&prerelease                

TypeUtilities

Build NuGet

Type Utilities provides a source generators to create/transform one type into another.

This project was inspired by the TypeScript Utility Types and was ment to bring similar functionality to the C# via source generators

Instalation

To use the the TypeUtilities, install the TypeUtilities package into your project.

To install the packages, add the references to your csproj file, for example by running

dotnet add package TypeUtilities --prerelease

This adds a <PackageReference> to your project. You can additionally mark the package as PrivateAsets="all" and ExcludeAssets="runtime".

Setting PrivateAssets="all" means any projects referencing this one will not also get a reference to the TypeUtilities package. Setting ExcludeAssets="runtime" ensures the TypeUtilities.Abstractions.dll file is not copied to your build output (it is not required at runtime).

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  
  <PackageReference Include="TypeUtilities" Version="0.0.1-alpha2" PrivateAssets="all" ExcludeAssets="runtime" />
  

</Project>

Usage

TypeUtilities provides several attributes:

Map

Map Attribute simply maps memebers of the source type to the target type using specified format.

using TypeUtilities;
using TypeUtilities.Abstractions;

public class SourceType
{
    public Guid Id { get; }
    public int Value { get; set; }
    public DateTime Created { get; set; }
}

[Map(typeof(SourceType))]
public partial class SimpleMap
{
}

// Generated result
//----- SimpleMap.map.SourceType.g.cs
public partial class SimpleMap
{
    public System.Guid Id { get; }
    public int Value { get; set; }
    public System.DateTime Created { get; set; }
}
// --------------------

[Map(typeof(SourceType),
      MemberDeclarationFormat = $"{Tokens.Accessibility} string Mapped{Tokens.    Name}{Tokens.Accessors}",
      MemberKindSelection = MemberKindFlags.ReadonlyProperty
    )]
public partial class AdvancedMap
{
}

// Generated result
//----- AdvancedMap.map.SourceType.g.cs
public partial class AdvancedMap
{
	  public string MappedId { get; }
}
// --------------------

Omit

Omit Attribute is similar to Map but also accepts an explicit list of members that should be exluded

using TypeUtilities;

public class SourceType
{
    public Guid Id { get; }
    public int Value { get; set; }
    public DateTime Created { get; set; }
}

[Omit(typeof(SourceType), "Value")]
public partial class TargetType
{
  public int MyValue { get; set; }
}

// Generated result
//----- TargetType.omit.SourceType.g.cs
public partial class TargetType
{
    public Guid Id { get; }
    public DateTime Created { get; set; }
}

Pick

Pick Attribute is similar to Map but also requires to explicitly specify all members that should be included

using TypeUtilities;

public class SourceType
{
    public Guid Id { get; }
    public int Value { get; set; }
    public DateTime Created { get; set; }
}

[Pick(typeof(SourceType), "Id", nameof(SourceType.Value))]
public partial class TargetType
{
}

// Generated result
//----- TargetType.omit.SourceType.g.cs
public partial class TargetType
{
    public Guid Id { get; }
    public int Value { get; set; }
}
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. 
.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.
  • .NETStandard 2.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
0.0.1 318 12/25/2022
0.0.1-beta01 142 7/16/2022
0.0.1-alpha2 130 6/5/2022
0.0.1-alpha1 129 5/29/2022