From 031fa9157a2d6c80f5d311b7c3a953cba64ff0dd Mon Sep 17 00:00:00 2001 From: Corniel Nobel Date: Wed, 21 Feb 2024 20:03:33 +0100 Subject: [PATCH] Immutabillity (#376) --- specs/Qowaiv.Specs/Hashing/Hash_specs.cs | 2 +- src/Qowaiv.TestTools/EmptyTestClassAttribute.cs | 2 +- src/Qowaiv.TestTools/SerializationWrapper.cs | 2 +- src/Qowaiv.TestTools/XmlStructure.TSvo.cs | 6 +++--- src/Qowaiv/Formatting/FormattingArgumentsCollection.cs | 4 ++-- src/Qowaiv/SingleValueObjectAttribute.cs | 2 +- src/Qowaiv/Text/WildcardPattern.cs | 10 +++++----- src/Qowaiv/Threading/ThreadDomain.cs | 6 +++--- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/specs/Qowaiv.Specs/Hashing/Hash_specs.cs b/specs/Qowaiv.Specs/Hashing/Hash_specs.cs index cc18b41a0..bff4e75e2 100644 --- a/specs/Qowaiv.Specs/Hashing/Hash_specs.cs +++ b/specs/Qowaiv.Specs/Hashing/Hash_specs.cs @@ -198,7 +198,7 @@ public void displays_the_hash() using (Hash.WithoutRandomizer()) { var hash = Hash.Code(12); - hash.ToString().Should().Be("12"); + hash.ToString().Should().Be("665630175"); } } } diff --git a/src/Qowaiv.TestTools/EmptyTestClassAttribute.cs b/src/Qowaiv.TestTools/EmptyTestClassAttribute.cs index 1ab6e8726..581cbcddd 100644 --- a/src/Qowaiv.TestTools/EmptyTestClassAttribute.cs +++ b/src/Qowaiv.TestTools/EmptyTestClassAttribute.cs @@ -12,5 +12,5 @@ public sealed class EmptyTestClassAttribute : Attribute { /// (Optional) justification for having this empty test class. - public string? Justification { get; set; } + public string? Justification { get; init; } } diff --git a/src/Qowaiv.TestTools/SerializationWrapper.cs b/src/Qowaiv.TestTools/SerializationWrapper.cs index 31a63bd87..bc73d6fe0 100644 --- a/src/Qowaiv.TestTools/SerializationWrapper.cs +++ b/src/Qowaiv.TestTools/SerializationWrapper.cs @@ -8,5 +8,5 @@ public sealed class SerializationWrapper { /// The generic part of the wrapper. - public T? Value { get; set; } + public T? Value { get; init; } } diff --git a/src/Qowaiv.TestTools/XmlStructure.TSvo.cs b/src/Qowaiv.TestTools/XmlStructure.TSvo.cs index 9ab2ee567..643ef7bc6 100644 --- a/src/Qowaiv.TestTools/XmlStructure.TSvo.cs +++ b/src/Qowaiv.TestTools/XmlStructure.TSvo.cs @@ -7,13 +7,13 @@ public sealed class XmlStructure where TSvo : struct { /// Gets and sets int property. - public int Id { get; set; } = 17; + public int Id { get; init; } = 17; /// Gets and sets SVO property. - public TSvo Svo { get; set; } + public TSvo Svo { get; init; } /// Gets and sets a date (time) property. - public DateTime Date { get; set; } = new DateTime(2017, 06, 11, 00, 00, 000, DateTimeKind.Utc); + public DateTime Date { get; init; } = new DateTime(2017, 06, 11, 00, 00, 000, DateTimeKind.Utc); /// [Pure] diff --git a/src/Qowaiv/Formatting/FormattingArgumentsCollection.cs b/src/Qowaiv/Formatting/FormattingArgumentsCollection.cs index 24f6a8768..836db387b 100644 --- a/src/Qowaiv/Formatting/FormattingArgumentsCollection.cs +++ b/src/Qowaiv/Formatting/FormattingArgumentsCollection.cs @@ -37,7 +37,7 @@ public FormattingArgumentsCollection(IFormatProvider? formatProvider, Formatting private readonly Dictionary dict = []; /// Gets the default format provider of the collection. - public IFormatProvider FormatProvider { get; protected set; } + public IFormatProvider FormatProvider { get; } /// Formats the object using the formatting arguments from the collection. /// @@ -476,7 +476,7 @@ public FormattingArguments Get(Type? type) } /// Gets a collection containing the types for the collection. - public ICollection Types => dict.Keys; + public IReadOnlyCollection Types => dict.Keys; /// Returns an enumerator that iterates through the collection. [Pure] diff --git a/src/Qowaiv/SingleValueObjectAttribute.cs b/src/Qowaiv/SingleValueObjectAttribute.cs index 31abb20ca..6cd211a89 100644 --- a/src/Qowaiv/SingleValueObjectAttribute.cs +++ b/src/Qowaiv/SingleValueObjectAttribute.cs @@ -34,5 +34,5 @@ public SingleValueObjectAttribute(SingleValueStaticOptions staticOptions, Type u /// /// Use this if the database type is different from the underlying type. /// - public Type? DatabaseType { get; set; } + public Type? DatabaseType { get; init; } } diff --git a/src/Qowaiv/Text/WildcardPattern.cs b/src/Qowaiv/Text/WildcardPattern.cs index d3f09277e..e3d4df59c 100644 --- a/src/Qowaiv/Text/WildcardPattern.cs +++ b/src/Qowaiv/Text/WildcardPattern.cs @@ -115,19 +115,19 @@ protected virtual void GetObjectData(SerializationInfo info, StreamingContext co } /// The wildcard pattern options. - public WildcardPatternOptions Options { get; private set; } + public WildcardPatternOptions Options { get; init; } /// The comparison type. - public StringComparison ComparisonType { get; private set; } + public StringComparison ComparisonType { get; init; } /// The wildcard pattern. - protected string Pattern { get; private set; } + protected string Pattern { get; init; } /// The wildcard single char. - protected char SingleChar { get; set; } + protected char SingleChar { get; init; } /// The wildcard multiple chars. - protected char MultipleChars { get; set; } + protected char MultipleChars { get; init; } /// Returns true if matching is culture independent, otherwise false. /// diff --git a/src/Qowaiv/Threading/ThreadDomain.cs b/src/Qowaiv/Threading/ThreadDomain.cs index 90b159551..84c2454a3 100644 --- a/src/Qowaiv/Threading/ThreadDomain.cs +++ b/src/Qowaiv/Threading/ThreadDomain.cs @@ -8,7 +8,7 @@ namespace Qowaiv.Threading; /// Represents domain of typed instances that can be used as the /// default values based on the current thread. /// -public class ThreadDomain +public sealed class ThreadDomain { /// Initializes static members of the class. static ThreadDomain() @@ -68,10 +68,10 @@ public static void Register(Type type, Func creator) /// /// No public accessor. /// - protected ThreadDomain() => Values = []; + private ThreadDomain() => Values = []; /// The underlying dictionary. - protected Dictionary Values { get; private set; } + private Dictionary Values { get; set; } /// Gets the current value of T. ///