Skip to content

Commit

Permalink
Introduction of Qowaiv.Diagnostics.Contracts package.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed Feb 17, 2024
1 parent b3d404c commit e670717
Show file tree
Hide file tree
Showing 29 changed files with 161 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Qowaiv.sln
Expand Up @@ -70,6 +70,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{7F291C
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Qowaiv.Benchmarks", "specs\Qowaiv.Benchmarks\Qowaiv.Benchmarks.csproj", "{6F2DEAC5-6E5D-4144-BA24-37039F387D67}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Qowaiv.Diagnostics.Contracts", "src\Qowaiv.Diagnostics.Contracts\Qowaiv.Diagnostics.Contracts.csproj", "{75090D12-3917-4CDD-8DDE-09B8407723A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -108,6 +110,10 @@ Global
{6F2DEAC5-6E5D-4144-BA24-37039F387D67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F2DEAC5-6E5D-4144-BA24-37039F387D67}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F2DEAC5-6E5D-4144-BA24-37039F387D67}.Release|Any CPU.Build.0 = Release|Any CPU
{75090D12-3917-4CDD-8DDE-09B8407723A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75090D12-3917-4CDD-8DDE-09B8407723A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75090D12-3917-4CDD-8DDE-09B8407723A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75090D12-3917-4CDD-8DDE-09B8407723A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion specs/Qowaiv.Benchmarks/Properties/GlobalUsings.cs
@@ -1,7 +1,7 @@
global using BenchmarkDotNet.Attributes;
global using MathNet.Numerics.Random;
global using Qowaiv.Diagnostics.Contracts;
global using Qowaiv.Financial;
global using Qowaiv.Diagnostics.Contracts;
global using Qowaiv.Globalization;
global using Qowaiv.Text;
global using System;
Expand Down
3 changes: 2 additions & 1 deletion specs/Qowaiv.Benchmarks/Qowaiv.Benchmarks.csproj
Expand Up @@ -24,10 +24,11 @@

<ItemGroup Label="Analyzers">
<PackageReference Include="FluentAssertions.Analyzers" Version="*" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="*" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="*" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Qowaiv.Diagnostics.Contracts\Qowaiv.Diagnostics.Contracts.csproj" />
<ProjectReference Include="..\..\src\Qowaiv\Qowaiv.csproj" />
<ProjectReference Include="..\..\src\Qowaiv.TestTools\Qowaiv.TestTools.csproj" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions specs/Qowaiv.Specs/Qowaiv.Specs.csproj
Expand Up @@ -31,6 +31,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Qowaiv.Diagnostics.Contracts\Qowaiv.Diagnostics.Contracts.csproj" />
<ProjectReference Include="..\..\src\Qowaiv\Qowaiv.csproj" />
<ProjectReference Include="..\..\src\Qowaiv.Data.SqlClient\Qowaiv.Data.SqlClient.csproj" />
<ProjectReference Include="..\..\src\Qowaiv.TestTools\Qowaiv.TestTools.csproj" />
Expand Down
@@ -0,0 +1,8 @@
namespace Qowaiv.Data.SqlClient.Internals.Diagnostics.Contracts;

/// <summary>To mark a method explicitly as impure. Methods decorated with
/// this attribute return the same instance that was provided as argument.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public sealed class FluentSyntaxAttribute : ImpureAttribute { }
@@ -0,0 +1,6 @@
namespace Qowaiv.Data.SqlClient.Internals.Diagnostics.Contracts;

/// <summary>To mark a method explicitly as impure.</summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public class ImpureAttribute : Attribute { }
@@ -0,0 +1,10 @@
namespace Qowaiv.Data.SqlClient.Internals.Diagnostics.Contracts;

/// <summary>Indicates the a class is designed to be inheritable.</summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public class InheritableAttribute : Attribute
{
/// <summary>Initializes a new instance of the <see cref="InheritableAttribute"/> class.</summary>
public InheritableAttribute(string? message = null) => _ = message;
}
2 changes: 1 addition & 1 deletion src/Qowaiv.Data.SqlClient/Properties/GlobalUsings.cs
@@ -1,4 +1,4 @@
global using Qowaiv.Diagnostics.Contracts;
global using Qowaiv.Data.SqlClient.Internals.Diagnostics.Contracts;
global using Qowaiv.Formatting;
global using Qowaiv.Hashing;
global using Qowaiv.OpenApi;
Expand Down
6 changes: 6 additions & 0 deletions src/Qowaiv.Diagnostics.Contracts/MutableAttribute.cs
@@ -0,0 +1,6 @@
namespace Qowaiv.Diagnostics.Contracts;

/// <summary>Indicates the class is designed to be mutable.</summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public sealed class MutableAttribute : Attribute { }
3 changes: 3 additions & 0 deletions src/Qowaiv.Diagnostics.Contracts/Properties/GlobalUsings.cs
@@ -0,0 +1,3 @@
global using System;
global using System.Diagnostics;
global using System.Resources;
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\props\package.props" />

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>1.0.0</Version>
<PackageId>Qowaiv.Diagnostics.Contracts</PackageId>
<PackageReleaseNotes>
v1.0.0
- Initial version.
</PackageReleaseNotes>
</PropertyGroup>

</Project>
31 changes: 31 additions & 0 deletions src/Qowaiv.Diagnostics.Contracts/README.md
@@ -0,0 +1,31 @@
# Qowaiv Diagnostics Contracts
This packages contains attributes to define (expected) behaviour on code.

## Impure attribute
Opposed to the `[Pure]` attribute, the `[Impure]` attribute indicates that a
method has side effects. This attribute can help working with static code
analyzer rule: [QW0003](https://github.com/Qowaiv/qowaiv-analyzers/blob/main/rules/QW0003.md).

### Collection mutation attribute
An attribute that inherits from `[Impure]` to indicate that the collection
changes due to this method call.

### Fluent syntax mutation attribute
An attribute that inherits from `[Impure]` to indicate that the returned
instance is equal to self or of the parameters, just to allow a fluent syntax.

## Inheritable attribute
The `[Inheritable]` attribute indicates that a class is designed to be
inheritable although no virtual or protected members have been defined.
This attribute can help working with static code analyzer rule: [QW0006](https://github.com/Qowaiv/qowaiv-analyzers/blob/main/rules/QW0006.md).

### Will be sealed attribute
An attribute that inherits from `[Inheritable]` that indicates that the
decorated member will be sealed in the future, and that overrides are considered
obsolete code.

## Mutable attribute
Indicates that a class, record, interface or struct is mutable by design.
This attribute can help working with static code analyzer rules:
[QW0011](https://github.com/Qowaiv/qowaiv-analyzers/blob/main/rules/QW0011.md)
and [QW0012](https://github.com/Qowaiv/qowaiv-analyzers/blob/main/rules/QW0012.md).
6 changes: 6 additions & 0 deletions src/Qowaiv.Diagnostics.Contracts/WillBeSealedAttribute.cs
@@ -0,0 +1,6 @@
namespace Qowaiv.Diagnostics.Contracts;

/// <summary>Indicates the class will be sealed with the next major change.</summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public sealed class WillBeSealedAttributee(string? message = null) : InheritableAttribute(message) { }
@@ -0,0 +1,8 @@
namespace Qowaiv.Testools.Internals.Diagnostics.Contracts;

/// <summary>To mark a method explicitly as impure. Methods decorated with
/// this attribute return the same instance that was provided as argument.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public sealed class FluentSyntaxAttribute : ImpureAttribute { }
@@ -0,0 +1,6 @@
namespace Qowaiv.Testools.Internals.Diagnostics.Contracts;

/// <summary>To mark a method explicitly as impure.</summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public class ImpureAttribute : Attribute { }
@@ -0,0 +1,10 @@
namespace Qowaiv.Testools.Internals.Diagnostics.Contracts;

/// <summary>Indicates the a class is designed to be inheritable.</summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public class InheritableAttribute : Attribute
{
/// <summary>Initializes a new instance of the <see cref="InheritableAttribute"/> class.</summary>
public InheritableAttribute(string? message = null) => _ = message;
}
2 changes: 1 addition & 1 deletion src/Qowaiv.TestTools/Properties/GlobalUsings.cs
@@ -1,5 +1,5 @@
global using Qowaiv;
global using Qowaiv.Diagnostics.Contracts;
global using Qowaiv.Testools.Internals.Diagnostics.Contracts;
global using System;
global using System.Collections;
global using System.Collections.Generic;
Expand Down
@@ -0,0 +1,8 @@
namespace Qowaiv.Internals.Diagnostics.Contracts;

/// <summary>To mark a method explicitly as impure. Methods decorated with
/// this attribute return info about (like, removal or addition was successful).
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
internal sealed class CollectionMutationAttribute : ImpureAttribute { }
@@ -0,0 +1,8 @@
namespace Qowaiv.Internals.Diagnostics.Contracts;

/// <summary>To mark a method explicitly as impure. Methods decorated with
/// this attribute return the same instance that was provided as argument.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public sealed class FluentSyntaxAttribute : ImpureAttribute { }
6 changes: 6 additions & 0 deletions src/Qowaiv/Internals/Diagnostics/Contracts/ImpureAttribute.cs
@@ -0,0 +1,6 @@
namespace Qowaiv.Internals.Diagnostics.Contracts;

/// <summary>To mark a method explicitly as impure.</summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public class ImpureAttribute : Attribute { }
10 changes: 10 additions & 0 deletions src/Qowaiv/Internals/Diagnostics/Contracts/InheritableAttribute.cs
@@ -0,0 +1,10 @@
namespace Qowaiv.Internals.Diagnostics.Contracts;

/// <summary>Indicates the a class is designed to be inheritable.</summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public class InheritableAttribute : Attribute
{
/// <summary>Initializes a new instance of the <see cref="InheritableAttribute"/> class.</summary>
public InheritableAttribute(string? message = null) => _ = message;
}
@@ -1,4 +1,4 @@
namespace Qowaiv.Diagnostics.Contracts;
namespace Qowaiv.Internals.Diagnostics.Contracts;

/// <summary>Indicates the class will be sealed with the next major change.</summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
Expand Down
@@ -1,6 +1,6 @@
using System.Reflection;

namespace Qowaiv.Diagnostics;
namespace Qowaiv.Internals.Diagnostics;

internal static class DebugDisplay
{
Expand Down
6 changes: 4 additions & 2 deletions src/Qowaiv/Properties/GlobalUsings.cs
@@ -1,8 +1,8 @@
global using Qowaiv.Conversion;
global using Qowaiv.Diagnostics;
global using Qowaiv.Diagnostics.Contracts;
global using Qowaiv.Formatting;
global using Qowaiv.Hashing;
global using Qowaiv.Internals.Diagnostics;
global using Qowaiv.Internals.Diagnostics.Contracts;
global using Qowaiv.OpenApi;
global using Qowaiv.Security;
global using Qowaiv.Text;
Expand All @@ -15,7 +15,9 @@
global using System.Diagnostics.Contracts;
global using System.Globalization;
global using System.Linq;
#if NET8_0_OR_GREATER
global using System.Numerics;
#endif
global using System.Resources;
global using System.Runtime.Serialization;
global using System.Text;
Expand Down
1 change: 1 addition & 0 deletions src/Qowaiv/Qowaiv.csproj
Expand Up @@ -30,6 +30,7 @@ v7.0.0
- Allign Parse and TryParse provider naming with IParsable. #360 (breaking)
- Drop support for .NET 5 and .NET 7 STS's. #359 (breaking)
- Deserializing ID's from JSON numeric nodes takes constrains into account. #374
- Move Qowaiv.Diagnostics.Contracs to a seperate package. (breaking)
v6.6.0
- Add former countries. #357
- Update display names countries (EN, DE, NL). #356
Expand Down

0 comments on commit e670717

Please sign in to comment.