Metalama.Patterns.Contracts 2024.2.10-preview

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

// Install Metalama.Patterns.Contracts as a Cake Tool
#tool nuget:?package=Metalama.Patterns.Contracts&version=2024.2.10-preview&prerelease                

Metalama Logo


The Metalama.Patterns.Contracts package implements the concept of contract-based programming, encompassing preconditions, postconditions, and invariants.

Key Features

  • Implementation of preconditions and postconditions through a wide range of numeric or string-based contracts.
  • Verification of invariants.

Main Types

Below is a list of available contract attributes for your selection:

Nullability Contracts

  • [NotNull] verifies that the assigned value is not null.
  • [Required] contract verifies that the value is not null and requires the string to be non-empty.

String Contracts

  • [NotEmpty] requires the string to be non-empty. Note that this contract does not validate the string against being null. If you want to prohibit both null and empty strings, use [Required].
  • [CreditCard] validates that the string is a valid credit card number.
  • [Email], [Phone], and [Url] validate strings against well-known regular expressions.
  • [Regex] validates a string against a custom regular expression.
  • [StringLength] validates that the length of a string falls within a specified range.

Enum Contracts

  • [EnumDataType] contract can validate values of type string, object, or of any integer type. It throws an exception if the value is not valid for the given enum type.

Numeric Contracts

The following contracts can be used to verify that a value falls within a specified range:

  • [LessThan] verifies that the value is less than or equal to the specified maximum.
  • [GreaterThan] verifies that the value is greater than or equal to the specified minimum.
  • [Negative] verifies that the value is less than or equal to zero.
  • [Positive] verifies that the value is greater than or equal to zero.
  • [Range] verifies that the value is greater than or equal to a specified minimum and less than or equal to a specified maximum.
  • [StrictlyLessThan] verifies that the value is strictly less than the specified maximum.
  • [StrictlyGreaterThan] verifies that the value is strictly greater than the specified minimum.
  • [StrictlyNegative] verifies that the value is strictly less than zero.
  • [StrictlyPositive] verifies that the value is strictly greater than zero.
  • [StrictRange] verifies that the value is strictly greater than a specified minimum and strictly less than a specified maximum.

Collections Contracts

  • [NotEmpty] contract can be used on any collection, including arrays or immutable arrays. It requires the collection or the array to contain at least one element.


  • [Invariant] causes the target method (a parameterless void method) to be invoked after each public method or property setter.
  • [DoNotCheckInvariants] exempts the target method from enforcing invariants, but does not exempt any method or property setter used by this method.
  • [SuspendInvariant] exempts the target method from enforcing invariants, including any method or property setter used by this method.

Additional Documentation

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 (5)

Showing the top 5 NuGet packages that depend on Metalama.Patterns.Contracts:

Package Downloads

Atesh.Metalama library is a collection of custom made Metalama Aspects (a.k.a Attributes).


A set of aspects that simplify the caching: [Cache] to cache a method result as a function of its parameters, [InvalidateCache] to invalidate the cache, or [CacheKey] to mark a cache key in a class.


Package Description


Provides custom


Automatically implements WPF dependency properties from a C# automatic property and WPF commands from a C# method thanks to Metalama.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2024.2.16-rc 16 7/18/2024
2024.2.15-rc 97 7/12/2024
2024.2.14-rc 126 7/8/2024
2024.2.13-rc 97 7/2/2024
2024.2.12-preview 134 6/28/2024
2024.2.11-preview 81 6/26/2024
2024.2.10-preview 91 6/20/2024
2024.2.9-preview 84 6/11/2024
2024.2.8-preview 68 6/6/2024
2024.2.7-preview 95 5/30/2024
2024.2.6-preview 92 5/25/2024
2024.2.5-preview 113 5/6/2024
2024.2.4-preview 102 5/4/2024
2024.2.3-preview 98 4/30/2024
2024.2.2-preview 98 4/23/2024
2024.2.1-preview 81 4/11/2024
2024.1.24 89 7/12/2024
2024.1.23 144 6/26/2024
2024.1.22 137 6/15/2024
2024.1.21 100 6/6/2024
2024.1.20 136 5/30/2024
2024.1.19 121 5/24/2024
2024.1.18 255 5/6/2024
2024.1.17 95 5/3/2024
2024.1.16 158 4/30/2024
2024.1.15 117 4/29/2024
2024.1.14 147 4/23/2024
2024.1.13 112 4/23/2024
2024.1.12 158 4/17/2024
2024.1.11-rc 101 4/11/2024
2024.1.10-rc 91 4/4/2024
2024.1.9-rc 91 3/27/2024
2024.1.8-preview 74 3/25/2024
2024.1.7-preview 104 3/19/2024
2024.1.6-preview 90 3/6/2024
2024.1.5-preview 90 2/29/2024
2024.1.4-preview 114 2/27/2024
2024.1.3-preview 98 2/23/2024
2024.1.2-preview 90 2/7/2024
2024.1.1-preview 72 1/30/2024
2024.0.16 110 6/15/2024
2024.0.15 96 6/6/2024
2024.0.14 104 5/30/2024
2024.0.13 109 5/24/2024
2024.0.12 136 4/17/2024
2024.0.11 138 3/21/2024
2024.0.10 104 3/19/2024
2024.0.9 146 2/29/2024
2024.0.8 134 2/23/2024
2024.0.7 137 2/7/2024
2024.0.6 184 1/3/2024
2024.0.5-rc 146 12/21/2023
2024.0.4-rc 127 12/12/2023
2024.0.3-preview 137 12/6/2023
2024.0.2-preview 140 11/14/2023
2024.0.1-preview 102 11/6/2023
2023.4.9 120 2/7/2024
2023.4.8 158 12/21/2023
2023.4.7 159 12/12/2023
2023.4.6 193 11/7/2023
2023.4.5-rc 125 10/26/2023
2023.4.4-preview 123 10/18/2023
2023.4.3-preview 97 10/4/2023
2023.4.2-preview 138 9/26/2023
2023.3.10-preview 122 12/21/2023
2023.3.9-preview 106 12/12/2023
2023.3.8-preview 122 10/17/2023
2023.3.7-preview 120 9/29/2023
2023.3.6-preview 124 9/26/2023
2023.3.5-preview 153 9/13/2023
2023.3.4-preview 155 8/30/2023