Skip to content

Commit

Permalink
Define justifications for all.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed Feb 18, 2024
1 parent dd38780 commit dd2bf68
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
Expand Up @@ -17,12 +17,12 @@ public void Fluent_syntax_attribute()

internal class SomeClass
{
[CollectionMutation]
[CollectionMutation("It just returns if addition worked.")]
public bool CollectionMutation(HashSet<SomeClass> set) => set.Add(this);

[Impure]
[Impure("It has side effects.")]
public static int Impure() => 42;

[FluentSyntax]
[FluentSyntax("We like fluent syntaxes.")]
public SomeClass FluentSyntax() => this;
}
Expand Up @@ -5,4 +5,4 @@
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public sealed class CollectionMutationAttribute : ImpureAttribute { }
public sealed class CollectionMutationAttribute(string? justification = null) : ImpureAttribute(justification) { }
2 changes: 1 addition & 1 deletion src/Qowaiv.Diagnostics.Contracts/FluentSyntaxAttribute.cs
Expand Up @@ -5,4 +5,4 @@
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public sealed class FluentSyntaxAttribute : ImpureAttribute { }
public sealed class FluentSyntaxAttribute(string? justification = null) : ImpureAttribute(justification) { }
6 changes: 5 additions & 1 deletion src/Qowaiv.Diagnostics.Contracts/ImpureAttribute.cs
Expand Up @@ -3,4 +3,8 @@
/// <summary>To mark a method explicitly as impure.</summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
[Conditional("CONTRACTS_FULL")]
public class ImpureAttribute : Attribute { }
public class ImpureAttribute(string? justification = null) : Attribute
{
/// <summary>THe justification of this decoration.</summary>
public string? Justification { get; init; } = justification;
}
6 changes: 3 additions & 3 deletions src/Qowaiv.Diagnostics.Contracts/InheritableAttribute.cs
Expand Up @@ -3,8 +3,8 @@
/// <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
public class InheritableAttribute(string? justification = null) : Attribute
{
/// <summary>Initializes a new instance of the <see cref="InheritableAttribute"/> class.</summary>
public InheritableAttribute(string? message = null) => _ = message;
/// <summary>THe justification of this decoration.</summary>
public string? Justification { get; init; } = justification;
}
6 changes: 3 additions & 3 deletions src/Qowaiv.Diagnostics.Contracts/MutableAttribute.cs
Expand Up @@ -3,8 +3,8 @@
/// <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
public sealed class MutableAttribute(string? justification = null) : Attribute
{
/// <summary>Initializes a new instance of the <see cref="MutableAttribute"/> class.</summary>
public MutableAttribute(string? message = null) => _ = message;
/// <summary>THe justification of this decoration.</summary>
public string? Justification { get; init; } = justification;
}
2 changes: 1 addition & 1 deletion src/Qowaiv.Diagnostics.Contracts/WillBeSealedAttribute.cs
Expand Up @@ -3,4 +3,4 @@
/// <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 WillBeSealedAttribute(string? message = null) : InheritableAttribute(message) { }
public sealed class WillBeSealedAttribute(string? justification = null) : InheritableAttribute(justification) { }

0 comments on commit dd2bf68

Please sign in to comment.