Skip to content

Latest commit

 

History

History
85 lines (64 loc) · 4.59 KB

README_BODY.md

File metadata and controls

85 lines (64 loc) · 4.59 KB

Immutype

NuGet License GitHub Build

Immutype is .NET code generator creating extension methods for records, structures, and classes marked by the attribute [Immutype.Target] to efficiently operate with instances of these types like with immutable ones.

For instance, for the type Foo for the constructor parameter values of type IEnumerable<int> following extension methods are generated:

  • Foo WithValues(this Foo it, params int[] values) - to replace values by the new ones using a method with variable number of arguments
  • Foo WithValues(this Foo it, IEnumerable<int> values) - to replace values by the new ones
  • Foo AddValues(this Foo it, params int[] values) - to add values using a method with variable number of arguments
  • Foo AddValues(this Foo it, IEnumerable<int> values) - to add values
  • Foo RemoveValues(this Foo it, params int[] values) - to remove values using a method with variable number of arguments
  • Foo RemoveValues(this Foo it, IEnumerable<int> values) - to remove values
  • Foo ClearValues(this Foo it) - to clear all values

For the type Foo for the constructor parameter value of other types, like int, with default value 99 following extension methods are generated:

  • Foo WithValue(this Foo it, int value) - to replace a value by the new one
  • Foo WithDefaultValue(this Foo it) - to replace a value by the default value 99

The extensions methods above are generating automatically for each public or internal type, like Foo marked by the attribute [Immutype.Target] in the static class named as FooExtensions. This generated class FooExtensions is static, has the same accessibility level and the same namespace like a target class Foo. Each generated static extension method has two attributes:

  • [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - to improve performance
  • [Pure] - to indicate that this method is pure, that is, it does not make any visible state changes

Immutype supports nullable reference and value types and the following list of enumerable types:

  • Arrays
  • IEnumerable<T>
  • List<T>
  • IList<T>
  • IReadOnlyCollection<T>
  • IReadOnlyList<T>
  • ICollection<T>
  • HashSet<T>
  • ISet<T>
  • Queue<T>
  • Stack<T>
  • IReadOnlyCollection<T>
  • IReadOnlyList<T>
  • IReadOnlySet<T>
  • ImmutableList<T>
  • IImmutableList<T>
  • ImmutableArray<T>
  • ImmutableQueue<T>
  • IImmutableQueue<T>
  • ImmutableStack<T>
  • IImmutableStack<T>

Immutype supports IIncrementalGenerator as well as ISourceGenerator so it works quite effective.

NuGet package

NuGet

  • Package Manager

    Install-Package Immutype
    
  • .NET CLI

    dotnet add package Immutype
    

Development environment requirements

Supported frameworks