Pretune 0.8.6

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

Pretune

Source-based C# preprocessor generating boilerplate code before compile.

Pros

  • Simple. The only things you have to do is adding Nuget package and annotating to class
  • Easy to debug. Can see the generated codes in IDE.
  • Depends on only .net 3.1 runtime.
  • No additional assembly dependencies embedded for publishing.
  • Using C# code as DSL, c# compiler will verify input is well-typed.

Features

Generate Constuctor <a name="auto_constructor"> </a>

Pretune generates constructor by adding 'AutoConstructor' attibute to class.

make this code

// MyClass.cs
[AutoConstructor]
partial class MyClass
{
    int a;
    string b;
}

and build then you will get following code

// PretuneGenerated/MyClass.g.cs
partial class MyClass
{
    public MyClass(int a, string b)
    {
        this.a = a;
        this.b = b;
    }
}

NOTICE Though this feature can be replaced by record of C# 9, it's still useful for the project that needs previous version of C#. And it also supports struct.

Implementing INotifyPropetyChanged <a name="implement_inotifypropertychanged"> </a>

make this code

// ViewModel.cs
[ImplementINotifyPropertyChanged]
public partial class ViewModel
{
    string firstName;
    string lastName;
    
    [DependsOn(nameof(firstName), nameof(lastName)]
    public string FamilyName { get => $"{firstName} {lastName}"; }
}    

and build then you will get following code

// PretuneGenerated/ViewModel.g.cs
partial class ViewModel
{
    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    public string FirstName
    {
        get => firstName;
        set
        {
            if (!firstName.Equals(value))
            {
                firstName = value;
                PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs("FirstName"));
                PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs("FamilyName"));
            }
        }
    }

    public string LastName
    {
        get => lastName;
        set
        {
            if (!lastName.Equals(value))
            {
                lastName = value;
                PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs("LastName"));
                PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs("FamilyName"));
            }
        }
    }
}

Implementing IEquatable <a name="implement_iequatable"> </a>

make this code

// Script.cs
using Pretune;

namespace N
{
    [ImplementIEquatable]
    public partial class Script
    {
        int x;
        public string Y { get; }
    }
}

and build then you will get following code

// PretuneGenerated/Script.g.cs
#nullable enable

using Pretune;

namespace N
{
    public partial class Script : System.IEquatable<Script>
    {
        public override bool Equals(object? obj) => Equals(obj as Script);
        public bool Equals(Script? other)
        {
            if (other == null)
                return false;
            if (!x.Equals(other.x))
                return false;
            if (!Y.Equals(other.Y))
                return false;
            return true;
        }

        public override int GetHashCode()
        {
            var hashCode = new System.HashCode();
            hashCode.Add(this.x.GetHashCode());
            hashCode.Add(this.Y.GetHashCode());
            return hashCode.ToHashCode();
        }
    }
}

Installation

Visual Studio

Add 'Pretune' package from nuget

CLI

dotnet add package Pretune

Requirements

  • .net core runtime 3.1
Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in 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.8.6 306 5/30/2023
0.8.3 513 7/27/2021
0.8.1 471 4/5/2021
0.6.4 567 1/10/2021
0.6.0 620 1/2/2021