Valuify 1.8.0

dotnet add package Valuify --version 1.8.0
                    
NuGet\Install-Package Valuify -Version 1.8.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="Valuify" Version="1.8.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Valuify" Version="1.8.0" />
                    
Directory.Packages.props
<PackageReference Include="Valuify">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 Valuify --version 1.8.0
                    
#r "nuget: Valuify, 1.8.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 Valuify@1.8.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=Valuify&version=1.8.0
                    
Install as a Cake Addin
#tool nuget:?package=Valuify&version=1.8.0
                    
Install as a Cake Tool

Valuify NuGet GitHub

Valuify is a .NET Roslyn source generator that gives regular class types record-like behavior (value equality, stable hashing, and descriptive ToString) without requiring C# 9+ records. It is intentionally optimized for engineers building IIncrementalGenerator pipelines where deterministic equality is critical for cache keys, memoized transforms, and repeatable outputs.

While Valuify is primarily designed with Roslyn source generators in mind, it also benefits legacy codebases that lack access to the record type introduced in C# 9.0. When used alongside Fluentify, a complementary Roslyn source generator that provides extension methods for creating projections, classes gain functionality equivalent to the with expression in records while preserving immutability and value-based equality.

Why engineers choose Valuify for Roslyn generators

  • Deterministic incremental caching: generated equality semantics help ensure generator inputs with equivalent values are treated as equal by incremental steps.
  • Record-like semantics on classes: generates IEquatable<T>, Equals, GetHashCode, ==, !=, and ToString for supported partial classes.
  • Low adoption cost: annotate a type with [Valuify] and continue using your existing class model.
  • Analyzer guidance included: bundled diagnostics guide correct usage and avoid unsupported declarations.

Quick start for generator authors

  1. Install Valuify in your generator project.
  2. Mark cache-key or model classes as partial and add [Valuify].
  3. Use those types in your incremental pipeline (Select, Combine, Collect) to improve cache hit behavior based on values, not object identity.
using Valuify;

[Valuify]
public partial class GenerationInput
{
    public string HintName { get; set; }

    public IReadOnlyList<string> Usings { get; set; }
}

Requirements

  • C# v2.0 or later.
  • Visual Studio 2022 v17.0 or later, or any compatible IDE that supports Roslyn source generators.

Installation

To install Valuify, use the following command in your package manager console:

install-package Valuify

Usage

Valuify automatically creates the code required to support property based equality on partial classes that have the Valuify attribute.

using Valuify;

[Valuify]
public partial class Property
{
    public string Name { get; set; }
    public string Type { get; set; }
}

Valuify will generate the following code for the above example:

Equality Operator (==)

The Equality Operator provides the code necessary to ensure that two instances are deemed equal based on their property values when checked using the == operator. When the type of a property is a scalar, the global::System.Collections.Generic.EqualityComparer<T>.Default instance is used to check for equality. When the type of a property implements System.Collections.IEnumerable, the global::Valuify.Internal.SequenceEqualityComparer is used, which ensures the instance associated with the property is checked for equality based on its contents, rather than its reference.

The following demonstrates the Equality Operator (==) code generated for Property type:

partial class Property
{
    public static bool operator ==(Property left, Property right)
    {
        if (ReferenceEquals(left, right))
        {
            return true;
        }

        if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
        {
            return false;
        }

        return left.Equals(right);
    }
}

The Equality Operator (==) is generated with a hintname that adheres to the following pattern:

{Fully Qualified Namespace}.{Type Name}.Equality.g.cs

The Equality Operator (==) will not be generated if the type explicitly defines an alternative implementation.

Equals Method Override

The Equals Method Override provides the code necessary to route calls directed towards the object.Equals(object) method to the IEquatable<T>.Equals(T) method.

The following demonstrates the Equals Method Override code generated for Property type:

partial class Property
{
    public override bool Equals(object other)
    {
        return Equals(other as Property);
    }
}

The Equals Method Override is generated with a hintname that adheres to the following pattern:

{Fully Qualified Namespace}.{Type Name}.Equals.g.cs

The Equals Method Override will not be generated if the type explicitly defines an alternative implementation.

Equatable Interface Annotation

The Equatable Interface Annotation provides the code necessary to ensure the type declares that it implements System.IEquatable<T>.

The following demonstrates the Equatable Interface Annotation code generated for Property type:

partial class Property
    : IEquatable<Property>
{
}

The Equatable Interface Annotation is generated with a hintname that adheres to the following pattern:

{Fully Qualified Namespace}.{Type Name}.IEquatable.g.cs

The Equatable Interface Annotation will not be generated if the type already declares that it implements the interface, either explicitly on the type declaration or via its base type.

Equatable Implementation

The Equatable Implementation provides the code necessary to implement the IEquatable<T>.Equals(T) method, which serves to route calls to the Equality Operator (==) for the type.

The following demonstrates the Equatable Implementation code generated for Property type:

partial class Property
{
    public bool Equals(Property other)
    {
        if (ReferenceEquals(this, other))
        {
            return true;
        }

        if (ReferenceEquals(other, null))
        {
            return false;
        }

        return global::System.Collections.Generic.EqualityComparer<string>.Default.Equals(Name, other.Name)
            && global::System.Collections.Generic.EqualityComparer<string>.Default.Equals(Type, other.Type);
    }
}

The Equatable Implementation is generated with a hintname that adheres to the following pattern:

{Fully Qualified Namespace}.{Type Name}.IEquatable.Equals.g.cs

The Equatable Implementation will not be generated if the type explicitly defines an alternative implementation.

GetHashCode Method Override

The GetHashCode Method Override provides the code necessary to override the base object.GetHashCode() method to generate a unique, or near-unique hash, based on the values for each property declared by the type. When the type of a property implements System.Collections.IEnumerable, the hash will account for the contents, rather than the collection reference. This is achieved using a custom implementation provided by global::Valuify.Internal.HashCode.Combine(object[]), which is akin to the HashCode.Combine implementation, introduced in C# 8.0.

The following demonstrates the GetHashCode Method Override code generated for Property type:

partial class Property
{
    public override int GetHashCode()
    {
        return global::Valuify.Internal.HashCode.Combine(Name, Type);
    }
}

The GetHashCode Method Override is generated with a hintname that adheres to the following pattern:

{Fully Qualified Namespace}.{Type Name}.GetHashCode.g.cs

The GetHashCode Method Override will not be generated if the type explicitly defines an alternative implementation.

Inequality Operator (!=)

The Inequality Operator (!=) provides the code necessary to ensure that two instances are deemed inequal based on differences in their property values when checked using the != operator. The implementation serves to route calls to the Equality Operator (==).

The following demonstrates the Inequality Operator (!=) code generated for Property type:

partial class Property
{
    public static bool operator !=(Property left, Property right)
    {
        return !(left == right);
    }
}

The Inequality Operator (!=) is generated with a hintname that adheres to the following pattern:

{Fully Qualified Namespace}.{Type Name}.Inequality.g.cs

The Inequality Operator (!=) will not be generated if the type explicitly defines an alternative implementation.

ToString Method Override

The ToString Method Override provides the code necessary to override the base object.ToString() method to generate a unique value based on the values for each property declared by the type. The output is similar to that produced by the record type, introduced in C# 9.0.

The following demonstrates the ToString Method Override code generated for Property type:

partial class Property
{
    public override string ToString()
    {
        return string.Format("Property { Name = {0}, Type = {1} }", Name, Type);
    }
}

The ToString Method Override is generated with a hintname that adheres to the following pattern:

{Fully Qualified Namespace}.{Type Name}.ToString.g.cs

The ToString Method Override will not be generated if the type explicitly defines an alternative implementation.

Property Exclusion

Specific properties can be excluded from consideration by Valuify using the Ignore attribute:

using Valuify;

[Valuify]
public partial class Property
{
    public string Name { get; set; }

    [Ignore]
    public string Type { get; set; }
}

This will change the generated code as follows:

Equatable Implementation

partial class Property
{
    public bool Equals(Property other)
    {
        if (ReferenceEquals(this, other))
        {
            return true;
        }

        if (ReferenceEquals(other, null))
        {
            return false;
        }

        return global::System.Collections.Generic.EqualityComparer<string>.Default.Equals(Name, other.Name);
    }
}

GetHashCode Method Override

partial class Property
{
    public override int GetHashCode()
    {
        return global::Valuify.Internal.HashCode.Combine(Name);
    }
}

ToString Method Override

partial class Property
{
    public override string ToString()
    {
        return string.Format("Property { Name = {0} }", Name);
    }
}

Analyzers

Valuify includes several analyzers to assist engineers with its usage. These are:

Rule ID Category Severity Notes
VALFY01 Usage Warning Type is not a class
VALFY02 Usage Warning Type is not marked as partial
VALFY03 Design Info Type does not declare any properties
VALFY04 Usage Info Type does not utilize Valuify
VALFY05 Design Warning Valuify cannot guarantee Equality

Contributing

Contributions are welcome - see the CONTRIBUTING.md file for details.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

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.