From 3f9262d6a9faf81fb6e649ceaa4de229515b1fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ga=C5=82=C4=99zowski?= Date: Thu, 7 Mar 2024 00:06:09 +0100 Subject: [PATCH] More nullability checks --- .../AnyExtensibility/AnyExtensibility.csproj | 2 +- .../AnyGenerators/AnyGenerators.csproj | 2 +- .../AnyGenerators/Root/InlineGenerators.cs | 23 +++++---- src/netstandard2.0/AnyRoot/AnyRoot.csproj | 2 +- .../Collections/AnyCollectionExtensions.cs | 30 ++++++------ .../AnySpecification/AnySpecification.cs | 9 ++-- .../AnySpecification/AnySpecification.csproj | 2 +- .../AnySpecification/BuilderSpecification.cs | 49 ++++++++++--------- .../AnySpecification/Fixtures/AreaEntity.cs | 6 +-- .../Fixtures/ConcreteDataStructure2.cs | 6 +-- .../AnySpecification/Fixtures/Feature.cs | 6 +-- .../Fixtures/FileExtension.cs | 4 +- .../Fixtures/FileNameWithoutExtension.cs | 8 +-- .../AnySpecification/Fixtures/GetSettable.cs | 6 +-- .../Fixtures/IncrementalType.cs | 6 +-- .../Fixtures/MyComplexObject.cs | 8 +-- .../Fixtures/MyInnerObject.cs | 6 +-- .../Fixtures/MyOwnPcCollection.cs | 7 +-- .../Fixtures/ObjectWithMethodInfo.cs | 2 +- .../Fixtures/RecursiveClass2.cs | 2 +- .../AnySpecification/Fixtures/Settable.cs | 8 +-- .../RecursionAndNestingSpecification.cs | 3 +- .../ReportedErrorsResolutionSpecification.cs | 2 +- .../ConstructorWrapper.cs | 2 +- .../TypeReflection/TypeReflection.csproj | 2 +- .../TypeReflectionSpecification.csproj | 2 +- 26 files changed, 104 insertions(+), 101 deletions(-) diff --git a/src/netstandard2.0/AnyExtensibility/AnyExtensibility.csproj b/src/netstandard2.0/AnyExtensibility/AnyExtensibility.csproj index d38893b..a82f15c 100644 --- a/src/netstandard2.0/AnyExtensibility/AnyExtensibility.csproj +++ b/src/netstandard2.0/AnyExtensibility/AnyExtensibility.csproj @@ -3,7 +3,7 @@ latest enable - CS8600;CS8602;CS8603 + nullable diff --git a/src/netstandard2.0/AnyGenerators/AnyGenerators.csproj b/src/netstandard2.0/AnyGenerators/AnyGenerators.csproj index f529ba4..5880a9e 100644 --- a/src/netstandard2.0/AnyGenerators/AnyGenerators.csproj +++ b/src/netstandard2.0/AnyGenerators/AnyGenerators.csproj @@ -2,7 +2,7 @@ latest enable - CS8600;CS8602;CS8603 + nullable net6.0;netstandard2.1 diff --git a/src/netstandard2.0/AnyGenerators/Root/InlineGenerators.cs b/src/netstandard2.0/AnyGenerators/Root/InlineGenerators.cs index 52f8ba1..7e57468 100644 --- a/src/netstandard2.0/AnyGenerators/Root/InlineGenerators.cs +++ b/src/netstandard2.0/AnyGenerators/Root/InlineGenerators.cs @@ -79,12 +79,12 @@ public static InlineGenerator> ListWith(T[] included) return InternalInlineGenerators.ListWith(included); } - public static InlineGenerator> SortedList(int length) + public static InlineGenerator> SortedList(int length) where TKey : notnull { return InternalInlineGenerators.SortedList(length); } - public static InlineGenerator> SortedList() + public static InlineGenerator> SortedList() where TKey : notnull { return InternalInlineGenerators.SortedList(); } @@ -115,7 +115,7 @@ public static InlineGenerator> SortedSet() return InternalInlineGenerators.SortedSet(); } - public static InlineGenerator> Dictionary(int length) + public static InlineGenerator> Dictionary(int length) where TKey : notnull { return InternalInlineGenerators.Dictionary(length); } @@ -136,13 +136,12 @@ public static InlineGenerator> ReadOnlyDiction // Used by reflection // public API // ReSharper disable once UnusedMember.Global - public static InlineGenerator> Dictionary() + public static InlineGenerator> Dictionary() where TKey : notnull { return InternalInlineGenerators.Dictionary(); } - - public static InlineGenerator> ConcurrentDictionary(int length) + public static InlineGenerator> ConcurrentDictionary(int length) where TKey : notnull { return InternalInlineGenerators.ConcurrentDictionary(length); } @@ -150,7 +149,7 @@ public static InlineGenerator> ConcurrentDict // Used by reflection // public API // ReSharper disable once UnusedMember.Global - public static InlineGenerator> ConcurrentDictionary() + public static InlineGenerator> ConcurrentDictionary() where TKey : notnull { return InternalInlineGenerators.ConcurrentDictionary(); } @@ -181,7 +180,7 @@ public static InlineGenerator> ConcurrentQueue() return InternalInlineGenerators.ConcurrentQueue(); } - public static InlineGenerator> SortedDictionary(int length) + public static InlineGenerator> SortedDictionary(int length) where TKey : notnull { return InternalInlineGenerators.SortedDictionary(length); } @@ -189,7 +188,7 @@ public static InlineGenerator> SortedDictionary> SortedDictionary() + public static InlineGenerator> SortedDictionary() where TKey : notnull { return InternalInlineGenerators.SortedDictionary(); } @@ -224,7 +223,7 @@ public static InlineGenerator From(T[] possibleValues) return InternalInlineGenerators.From(possibleValues); } - public static InlineGenerator> DictionaryWithKeys(IEnumerable keys) + public static InlineGenerator> DictionaryWithKeys(IEnumerable keys) where TKey : notnull { return InternalInlineGenerators.DictionaryWithKeys(keys); } @@ -564,7 +563,7 @@ public static InlineGenerator> ImmutableSortedSet() // Used by reflection // public API // ReSharper disable once UnusedMember.Global - public static InlineGenerator> ImmutableDictionary() + public static InlineGenerator> ImmutableDictionary() where T1 : notnull { return InternalInlineGenerators.ImmutableDictionary(); } @@ -572,7 +571,7 @@ public static InlineGenerator> ImmutableDictionary> ImmutableSortedDictionary() + public static InlineGenerator> ImmutableSortedDictionary() where T1 : notnull { return InternalInlineGenerators.ImmutableSortedDictionary(); } diff --git a/src/netstandard2.0/AnyRoot/AnyRoot.csproj b/src/netstandard2.0/AnyRoot/AnyRoot.csproj index 143a377..b62892c 100644 --- a/src/netstandard2.0/AnyRoot/AnyRoot.csproj +++ b/src/netstandard2.0/AnyRoot/AnyRoot.csproj @@ -2,7 +2,7 @@ latest enable - CS8600;CS8602;CS8603 + nullable diff --git a/src/netstandard2.0/AnyRoot/Collections/AnyCollectionExtensions.cs b/src/netstandard2.0/AnyRoot/Collections/AnyCollectionExtensions.cs index 9b9b7d1..34be563 100644 --- a/src/netstandard2.0/AnyRoot/Collections/AnyCollectionExtensions.cs +++ b/src/netstandard2.0/AnyRoot/Collections/AnyCollectionExtensions.cs @@ -120,12 +120,12 @@ public static IReadOnlyList ReadOnlyListWithout(this BasicGenerator gen, p return gen.InstanceOf(InlineGenerators.ListWithout(items)); } - public static SortedList SortedList(this BasicGenerator gen) + public static SortedList SortedList(this BasicGenerator gen) where TKey : notnull { return gen.InstanceOf(InlineGenerators.SortedList()); } - public static SortedList SortedList(this BasicGenerator gen, int length) + public static SortedList SortedList(this BasicGenerator gen, int length) where TKey : notnull { return gen.InstanceOf(InlineGenerators.SortedList(length)); } @@ -151,17 +151,17 @@ public static ISet SortedSet(this BasicGenerator gen) return gen.InstanceOf(InlineGenerators.SortedSet()); } - public static Dictionary Dictionary(this BasicGenerator gen, int length) + public static Dictionary Dictionary(this BasicGenerator gen, int length) where TKey : notnull { return gen.InstanceOf(InlineGenerators.Dictionary(length)); } - public static Dictionary DictionaryWithKeys(this BasicGenerator gen, IEnumerable keys) + public static Dictionary DictionaryWithKeys(this BasicGenerator gen, IEnumerable keys) where TKey : notnull { - return gen.InstanceOf(InlineGenerators.DictionaryWithKeys(keys)); + return gen.InstanceOf(InlineGenerators.DictionaryWithKeys(keys)); } - public static Dictionary Dictionary(this BasicGenerator gen) + public static Dictionary Dictionary(this BasicGenerator gen) where TKey : notnull { return gen.InstanceOf(InlineGenerators.Dictionary()); } @@ -171,7 +171,7 @@ public static IReadOnlyDictionary ReadOnlyDictionary return gen.InstanceOf(InlineGenerators.ReadOnlyDictionary(length)); } - public static IReadOnlyDictionary ReadOnlyDictionaryWithKeys(this BasicGenerator gen, IEnumerable keys) + public static IReadOnlyDictionary ReadOnlyDictionaryWithKeys(this BasicGenerator gen, IEnumerable keys) where TKey : notnull { return gen.InstanceOf(InlineGenerators.DictionaryWithKeys(keys)); } @@ -181,22 +181,22 @@ public static IReadOnlyDictionary ReadOnlyDictionary return gen.InstanceOf(InlineGenerators.ReadOnlyDictionary()); } - public static SortedDictionary SortedDictionary(this BasicGenerator gen, int length) + public static SortedDictionary SortedDictionary(this BasicGenerator gen, int length) where TKey : notnull { return gen.InstanceOf(InlineGenerators.SortedDictionary(length)); } - public static SortedDictionary SortedDictionary(this BasicGenerator gen) + public static SortedDictionary SortedDictionary(this BasicGenerator gen) where TKey : notnull { return gen.InstanceOf(InlineGenerators.SortedDictionary()); } - public static ConcurrentDictionary ConcurrentDictionary(this BasicGenerator gen, int length) + public static ConcurrentDictionary ConcurrentDictionary(this BasicGenerator gen, int length) where TKey : notnull { return gen.InstanceOf(InlineGenerators.ConcurrentDictionary(length)); } - public static ConcurrentDictionary ConcurrentDictionary(this BasicGenerator gen) + public static ConcurrentDictionary ConcurrentDictionary(this BasicGenerator gen) where TKey : notnull { return gen.InstanceOf(InlineGenerators.ConcurrentDictionary()); } @@ -263,14 +263,14 @@ public static ImmutableSortedSet ImmutableSortedSet(this BasicGenerator ge return gen.InstanceOf(InlineGenerators.ImmutableSortedSet()); } - public static ImmutableDictionary ImmutableDictionary(this BasicGenerator gen) + public static ImmutableDictionary ImmutableDictionary(this BasicGenerator gen) where TKey : notnull { - return gen.InstanceOf(InlineGenerators.ImmutableDictionary()); + return gen.InstanceOf(InlineGenerators.ImmutableDictionary()); } - public static ImmutableSortedDictionary ImmutableSortedDictionary(this BasicGenerator gen) + public static ImmutableSortedDictionary ImmutableSortedDictionary(this BasicGenerator gen) where TKey : notnull { - return gen.InstanceOf(InlineGenerators.ImmutableSortedDictionary()); + return gen.InstanceOf(InlineGenerators.ImmutableSortedDictionary()); } public static ImmutableQueue ImmutableQueue(this BasicGenerator gen) diff --git a/src/netstandard2.0/AnySpecification/AnySpecification.cs b/src/netstandard2.0/AnySpecification/AnySpecification.cs index 0a0be9b..822d1c5 100644 --- a/src/netstandard2.0/AnySpecification/AnySpecification.cs +++ b/src/netstandard2.0/AnySpecification/AnySpecification.cs @@ -13,6 +13,7 @@ using System.Threading.Tasks; using AnySpecification.Fixtures; using AnySpecification.GraphComparison; +using Core.NullableReferenceTypesExtensions; using FluentAssertions; using Functional.Maybe; using Newtonsoft.Json; @@ -382,7 +383,7 @@ public void ShouldDisallowSkippingTheSameValueTwiceWhenGeneratingAnyValueOtherTh } [Test, CancelAfter(2000)] - public async Task ShouldDisallowSkippingAllEnumMembers(CancellationToken ct) + public void ShouldDisallowSkippingAllEnumMembers() { Any.Invoking(a => a.OtherThan( LolEnum.Value2, @@ -992,8 +993,8 @@ public void ShouldAllowCustomizationsToReachInnerAutoFixture() })); anyConcrete.DummyString.Should().Be("CustomString"); - anyConcrete.Inner.InnerDummyInt.Should().Be(123); - anyConcrete.Inner.InnerDummyString.Should().Be("InnerCustomString"); + anyConcrete.Inner.OrThrow().InnerDummyInt.Should().Be(123); + anyConcrete.Inner.OrThrow().InnerDummyString.Should().Be("InnerCustomString"); } [TestCase(LolEnum.Value1)] @@ -1876,7 +1877,7 @@ private static void CallSomeMethodsOn(AbstractObjectWithInterfaceInConstructor x RecursiveInterface x3) { // ReSharper disable once UnusedVariable - _ = new object[] {x1.AbstractInt, x2.GetSomething(), x3.NestedAsDictionary, x2.GetSomething2(), x3.Nested}; + _ = new object[] {x1.AbstractInt, x2.GetSomething().OrThrow(), x3.NestedAsDictionary, x2.GetSomething2(), x3.Nested}; } private static void SerializeAnyInstanceOf() diff --git a/src/netstandard2.0/AnySpecification/AnySpecification.csproj b/src/netstandard2.0/AnySpecification/AnySpecification.csproj index eb5d09c..e80182e 100644 --- a/src/netstandard2.0/AnySpecification/AnySpecification.csproj +++ b/src/netstandard2.0/AnySpecification/AnySpecification.csproj @@ -2,7 +2,7 @@ latest enable - CS8600;CS8602;CS8603 + nullable diff --git a/src/netstandard2.0/AnySpecification/BuilderSpecification.cs b/src/netstandard2.0/AnySpecification/BuilderSpecification.cs index a1e4c6f..f8c3013 100644 --- a/src/netstandard2.0/AnySpecification/BuilderSpecification.cs +++ b/src/netstandard2.0/AnySpecification/BuilderSpecification.cs @@ -1,4 +1,5 @@ using System; +using Core.NullableReferenceTypesExtensions; using FluentAssertions; using TddXt.AnyRoot.Builder; @@ -9,28 +10,28 @@ class BuilderSpecification [Test, Parallelizable] public void ShouldAllowSettingNestedSettableAutoProperties() { - Any.Instance().WithProperty(d => d.Nested.SettableStringValue, "lol") - .Nested.SettableStringValue.Should().Be("lol"); + Any.Instance().WithProperty(d => d.Nested!.SettableStringValue, "lol") + .Nested.OrThrow().SettableStringValue.Should().Be("lol"); } [Test, Parallelizable] public void ShouldAllowSettingNestedNonSettableAutoProperties() { - Any.Instance().WithProperty(d => d.Nested.StringValue, "lol") - .Nested.StringValue.Should().Be("lol"); + Any.Instance().WithProperty(d => d.Nested!.StringValue, "lol") + .Nested.OrThrow().StringValue.Should().Be("lol"); } [Test, Parallelizable] public void ShouldThrowWhenSettingPropertyOfUninitializedProperty() { - Any.Instance().Invoking(d => d.WithProperty(d => d.NestedNotInitializedFromConstructor.StringValue, "lol")) + Any.Instance().Invoking(d => d.WithProperty(d => d.NestedNotInitializedFromConstructor!.StringValue, "lol")) .Should().Throw(); } [Test, Parallelizable] public void ShouldThrowWhenInvokedOnNull() { - new Action(() => (null as DataStructure)!.WithProperty(d => d!.NestedNotInitializedFromConstructor.StringValue, "lol")) + new Action(() => (null as DataStructure)!.WithProperty(d => d.NestedNotInitializedFromConstructor!.StringValue, "lol")) .Should().Throw(); } @@ -44,7 +45,7 @@ public void ShouldThrowWhenSettingPropertyOfMethodReturnValue() [Test, Parallelizable] public void ShouldThrowWhenSettingNonAutoNonSettableProperty() { - Any.Instance().Invoking(d => d.WithProperty(d => d.Nested.NonAutoStringValue, "lol")) + Any.Instance().Invoking(d => d.WithProperty(d => d.Nested!.NonAutoStringValue, "lol")) .Should().Throw(); } @@ -53,31 +54,31 @@ public void ShouldThrowWhenSettingNonAutoNonSettableProperty() [Test, Parallelizable] public void ShouldAllowSettingPublicFieldThroughProperty() { - Any.Instance().WithProperty(d => d.Nested.StringField, "lol") - .Nested.StringField.Should().Be("lol"); + Any.Instance().WithProperty(d => d.Nested!.StringField, "lol") + .Nested.OrThrow().StringField.Should().Be("lol"); } [Test, Parallelizable] public void ShouldAllowSettingPublicFieldThroughField() { - Any.Instance().WithProperty(d => d.NestedField.StringField, "lol") - .NestedField.StringField.Should().Be("lol"); + Any.Instance().WithProperty(d => d.NestedField!.StringField, "lol") + .NestedField.OrThrow().StringField.Should().Be("lol"); } [Test, Parallelizable] public void ShouldAllowSettingPublicFieldThroughReadOnlyField() { var dataStructure = Any.Instance(); - dataStructure.WithProperty(d => d.NestedReadOnlyField.StringField, "lol") - .NestedReadOnlyField.StringField.Should().Be("lol"); + dataStructure.WithProperty(d => d.NestedReadOnlyField!.StringField, "lol") + .NestedReadOnlyField.OrThrow().StringField.Should().Be("lol"); } [Test, Parallelizable] public void ShouldAllowSettingPropertyThroughPublicField() { var dataStructure = Any.Instance(); - dataStructure.WithProperty(d => d.NestedReadOnlyField.SettableStringValue, "lol") - .NestedReadOnlyField.SettableStringValue.Should().Be("lol"); + dataStructure.WithProperty(d => d.NestedReadOnlyField!.SettableStringValue, "lol") + .NestedReadOnlyField.OrThrow().SettableStringValue.Should().Be("lol"); } } @@ -88,17 +89,17 @@ public DataStructure(NestedDataStructure nested) Nested = nested; } - public NestedDataStructure Nested { get; } - public NestedDataStructure NestedField; - public NestedDataStructure NestedReadOnlyField; - public NestedDataStructure NestedNotInitializedFromConstructor { get; } - public NestedDataStructure GetNested() => new NestedDataStructure(); + public NestedDataStructure? Nested { get; } + public NestedDataStructure? NestedField; + public NestedDataStructure? NestedReadOnlyField; + public NestedDataStructure? NestedNotInitializedFromConstructor { get; } + public NestedDataStructure GetNested() => new(); } public class NestedDataStructure { - public string StringField; - public string StringValue { get; } - public string SettableStringValue { get; set; } + public string? StringField; + public string? StringValue { get; } + public string? SettableStringValue { get; set; } public string NonAutoStringValue => ""; -} \ No newline at end of file +} diff --git a/src/netstandard2.0/AnySpecification/Fixtures/AreaEntity.cs b/src/netstandard2.0/AnySpecification/Fixtures/AreaEntity.cs index 051a9ee..5d3d10d 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/AreaEntity.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/AreaEntity.cs @@ -1,6 +1,6 @@ -namespace AnySpecification.Fixtures; +namespace AnySpecification.Fixtures; public class AreaEntity { - public Feature Feature { get; set; } -} \ No newline at end of file + public Feature? Feature { get; set; } +} diff --git a/src/netstandard2.0/AnySpecification/Fixtures/ConcreteDataStructure2.cs b/src/netstandard2.0/AnySpecification/Fixtures/ConcreteDataStructure2.cs index 15a63d5..ea3f544 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/ConcreteDataStructure2.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/ConcreteDataStructure2.cs @@ -1,6 +1,6 @@ -namespace AnySpecification.Fixtures; +namespace AnySpecification.Fixtures; public class ConcreteDataStructure2 { - public string Text { get; set; } -} \ No newline at end of file + public string? Text { get; set; } +} diff --git a/src/netstandard2.0/AnySpecification/Fixtures/Feature.cs b/src/netstandard2.0/AnySpecification/Fixtures/Feature.cs index a1a0317..8920900 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/Feature.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/Feature.cs @@ -1,9 +1,9 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace AnySpecification.Fixtures; [SuppressMessage("ReSharper", "UnusedMember.Global")] public class Feature { - public IGeometry Geometry { get; set; } -} \ No newline at end of file + public IGeometry? Geometry { get; set; } +} diff --git a/src/netstandard2.0/AnySpecification/Fixtures/FileExtension.cs b/src/netstandard2.0/AnySpecification/Fixtures/FileExtension.cs index ea749a0..946e37e 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/FileExtension.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/FileExtension.cs @@ -12,7 +12,7 @@ internal FileExtension(string extension) _extension = extension; } - public bool Equals(FileExtension other) + public bool Equals(FileExtension? other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; @@ -33,7 +33,7 @@ public static FileExtension Value(string extensionString) return new FileExtension(extensionString); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; diff --git a/src/netstandard2.0/AnySpecification/Fixtures/FileNameWithoutExtension.cs b/src/netstandard2.0/AnySpecification/Fixtures/FileNameWithoutExtension.cs index 9cbc9a0..7779b12 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/FileNameWithoutExtension.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/FileNameWithoutExtension.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace AnySpecification.Fixtures; @@ -11,7 +11,7 @@ internal FileNameWithoutExtension(string value) _value = value; } - public bool Equals(FileNameWithoutExtension other) + public bool Equals(FileNameWithoutExtension? other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; @@ -23,7 +23,7 @@ public static FileNameWithoutExtension Value(string fileNameWithoutExtensionStri return new FileNameWithoutExtension(fileNameWithoutExtensionString); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; @@ -50,4 +50,4 @@ public override string ToString() { return _value; } -} \ No newline at end of file +} diff --git a/src/netstandard2.0/AnySpecification/Fixtures/GetSettable.cs b/src/netstandard2.0/AnySpecification/Fixtures/GetSettable.cs index a3ec518..6513ec9 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/GetSettable.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/GetSettable.cs @@ -1,6 +1,6 @@ -namespace AnySpecification.Fixtures; +namespace AnySpecification.Fixtures; public abstract class GetSettable { - public T Value { get; set; } -} \ No newline at end of file + public T? Value { get; set; } +} diff --git a/src/netstandard2.0/AnySpecification/Fixtures/IncrementalType.cs b/src/netstandard2.0/AnySpecification/Fixtures/IncrementalType.cs index 870f998..615ceb5 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/IncrementalType.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/IncrementalType.cs @@ -14,7 +14,7 @@ public IncrementalType(int x, string y) public int X { get; set; } - public bool Equals(IncrementalType other) + public bool Equals(IncrementalType? other) { throw new NotImplementedException(); } @@ -29,7 +29,7 @@ public bool Equals(IncrementalType other) return true; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { return false; } @@ -38,4 +38,4 @@ public override int GetHashCode() { return 0; } -} \ No newline at end of file +} diff --git a/src/netstandard2.0/AnySpecification/Fixtures/MyComplexObject.cs b/src/netstandard2.0/AnySpecification/Fixtures/MyComplexObject.cs index 0fa6910..20a32fb 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/MyComplexObject.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/MyComplexObject.cs @@ -1,7 +1,7 @@ -namespace AnySpecification.Fixtures; +namespace AnySpecification.Fixtures; public class MyComplexObject { - public string DummyString { get; set; } - public MyInnerObject Inner { get; set; } -} \ No newline at end of file + public string? DummyString { get; set; } + public MyInnerObject? Inner { get; set; } +} diff --git a/src/netstandard2.0/AnySpecification/Fixtures/MyInnerObject.cs b/src/netstandard2.0/AnySpecification/Fixtures/MyInnerObject.cs index 2c4c071..0740d45 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/MyInnerObject.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/MyInnerObject.cs @@ -1,8 +1,8 @@ -namespace AnySpecification.Fixtures; +namespace AnySpecification.Fixtures; public class MyInnerObject { public int InnerDummyInt { get; set; } - public string InnerDummyString { get; set; } -} \ No newline at end of file + public string? InnerDummyString { get; set; } +} diff --git a/src/netstandard2.0/AnySpecification/Fixtures/MyOwnPcCollection.cs b/src/netstandard2.0/AnySpecification/Fixtures/MyOwnPcCollection.cs index b9ee09c..30fde84 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/MyOwnPcCollection.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/MyOwnPcCollection.cs @@ -1,7 +1,8 @@ -using System; +using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace AnySpecification.Fixtures; @@ -44,8 +45,8 @@ public bool TryAdd(T item) return _inner.TryAdd(item); } - public bool TryTake(out T item) + public bool TryTake([MaybeNullWhen(false)] out T item) { return _inner.TryTake(out item); } -} \ No newline at end of file +} diff --git a/src/netstandard2.0/AnySpecification/Fixtures/ObjectWithMethodInfo.cs b/src/netstandard2.0/AnySpecification/Fixtures/ObjectWithMethodInfo.cs index 7affac7..7a5ddf2 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/ObjectWithMethodInfo.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/ObjectWithMethodInfo.cs @@ -4,5 +4,5 @@ namespace AnySpecification.Fixtures; public class ObjectWithMethodInfo { - public MethodInfo Method { get; set; } + public MethodInfo? Method { get; set; } } diff --git a/src/netstandard2.0/AnySpecification/Fixtures/RecursiveClass2.cs b/src/netstandard2.0/AnySpecification/Fixtures/RecursiveClass2.cs index 7187641..6588e73 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/RecursiveClass2.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/RecursiveClass2.cs @@ -2,5 +2,5 @@ public class RecursiveClass2 { - public RecursiveClass Other { get; set; } + public RecursiveClass? Other { get; set; } } diff --git a/src/netstandard2.0/AnySpecification/Fixtures/Settable.cs b/src/netstandard2.0/AnySpecification/Fixtures/Settable.cs index 899e5e6..b88e72e 100644 --- a/src/netstandard2.0/AnySpecification/Fixtures/Settable.cs +++ b/src/netstandard2.0/AnySpecification/Fixtures/Settable.cs @@ -1,12 +1,12 @@ -namespace AnySpecification.Fixtures; +namespace AnySpecification.Fixtures; public abstract class Settable { - private T _value; + private T? _value; - public T Value + public T? Value { set => _value = value; private get => _value; } -} \ No newline at end of file +} diff --git a/src/netstandard2.0/AnySpecification/RecursionAndNestingSpecification.cs b/src/netstandard2.0/AnySpecification/RecursionAndNestingSpecification.cs index 28d4bc4..cda6252 100644 --- a/src/netstandard2.0/AnySpecification/RecursionAndNestingSpecification.cs +++ b/src/netstandard2.0/AnySpecification/RecursionAndNestingSpecification.cs @@ -57,7 +57,8 @@ public void ShouldRespectNestingLimit() var instance = Any.Instance(); //THEN - ClassicAssert.AreEqual(1, instance.Others.OrThrow()[0].Other.Others.OrThrow()[0].Other.Others.OrThrow().Length, + ClassicAssert.AreEqual(1, + instance.Others.OrThrow()[0].Other.OrThrow().Others.OrThrow()[0].Other.OrThrow().Others.OrThrow().Length, "Dummy algorithm generates an empty collection"); } diff --git a/src/netstandard2.0/AnySpecification/ReportedErrorsResolutionSpecification.cs b/src/netstandard2.0/AnySpecification/ReportedErrorsResolutionSpecification.cs index be940eb..ccc6f05 100644 --- a/src/netstandard2.0/AnySpecification/ReportedErrorsResolutionSpecification.cs +++ b/src/netstandard2.0/AnySpecification/ReportedErrorsResolutionSpecification.cs @@ -18,7 +18,7 @@ public void ShouldFillProperties() public class UploadPayloadDto { - public MigrationDataDto MigrationData { get; set; } + public MigrationDataDto? MigrationData { get; set; } } public record MigrationDataDto diff --git a/src/netstandard2.0/TypeReflection/ImplementationDetails/ConstructorWrapper.cs b/src/netstandard2.0/TypeReflection/ImplementationDetails/ConstructorWrapper.cs index 395ca29..f075598 100644 --- a/src/netstandard2.0/TypeReflection/ImplementationDetails/ConstructorWrapper.cs +++ b/src/netstandard2.0/TypeReflection/ImplementationDetails/ConstructorWrapper.cs @@ -138,7 +138,7 @@ public void LogInScopeOf(GenerationRequest request) public static ConstructorWrapper FromConstructorInfo(ConstructorInfo constructor) { - return new ConstructorWrapper(constructor, constructor.Invoke, constructor.GetParameters(), constructor.DeclaringType); + return new ConstructorWrapper(constructor, constructor.Invoke, constructor.GetParameters(), constructor.DeclaringType.OrThrow()); } public static ConstructorWrapper FromStaticMethodInfo(MethodInfo m) diff --git a/src/netstandard2.0/TypeReflection/TypeReflection.csproj b/src/netstandard2.0/TypeReflection/TypeReflection.csproj index 85010da..a10a15e 100644 --- a/src/netstandard2.0/TypeReflection/TypeReflection.csproj +++ b/src/netstandard2.0/TypeReflection/TypeReflection.csproj @@ -2,7 +2,7 @@ latest enable - CS8600;CS8602;CS8603 + nullable diff --git a/src/netstandard2.0/TypeReflectionSpecification/TypeReflectionSpecification.csproj b/src/netstandard2.0/TypeReflectionSpecification/TypeReflectionSpecification.csproj index e75a3a9..eb5e37a 100644 --- a/src/netstandard2.0/TypeReflectionSpecification/TypeReflectionSpecification.csproj +++ b/src/netstandard2.0/TypeReflectionSpecification/TypeReflectionSpecification.csproj @@ -2,7 +2,7 @@ latest enable - CS8600;CS8602;CS8603 + nullable