diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 1f74b4969f..4467c16093 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -27,7 +27,7 @@ ] }, "csharpier": { - "version": "0.28.2", + "version": "0.29.1", "commands": [ "dotnet-csharpier" ] diff --git a/benchmarks/Riok.Mapperly.Benchmarks/SourceGeneratorBenchmarks.cs b/benchmarks/Riok.Mapperly.Benchmarks/SourceGeneratorBenchmarks.cs index c6c6aafd3c..5491fafecd 100644 --- a/benchmarks/Riok.Mapperly.Benchmarks/SourceGeneratorBenchmarks.cs +++ b/benchmarks/Riok.Mapperly.Benchmarks/SourceGeneratorBenchmarks.cs @@ -71,7 +71,7 @@ private static string GetDirectoryRelativePath(string projectPath, [CallerFilePa var generator = new MapperGenerator().AsSourceGenerator(); - var driver = CSharpGeneratorDriver.Create(new[] { generator }, parseOptions: (CSharpParseOptions)project.ParseOptions!); + var driver = CSharpGeneratorDriver.Create([generator], parseOptions: (CSharpParseOptions)project.ParseOptions!); return (compilation, driver); } diff --git a/samples/Riok.Mapperly.Sample/Car.cs b/samples/Riok.Mapperly.Sample/Car.cs index 6b4eca9a69..64f0cc07e5 100644 --- a/samples/Riok.Mapperly.Sample/Car.cs +++ b/samples/Riok.Mapperly.Sample/Car.cs @@ -10,7 +10,7 @@ public class Car public Manufacturer? Manufacturer { get; set; } - public List Tires { get; } = new List(); + public List Tires { get; } = []; } public enum CarColor diff --git a/src/Riok.Mapperly.Abstractions/PropertyNameMappingStrategy.cs b/src/Riok.Mapperly.Abstractions/PropertyNameMappingStrategy.cs index 6af336dc73..73f7e7b0a2 100644 --- a/src/Riok.Mapperly.Abstractions/PropertyNameMappingStrategy.cs +++ b/src/Riok.Mapperly.Abstractions/PropertyNameMappingStrategy.cs @@ -13,5 +13,5 @@ public enum PropertyNameMappingStrategy /// /// Matches a property by its name in case insensitive manner. /// - CaseInsensitive + CaseInsensitive, } diff --git a/src/Riok.Mapperly.Abstractions/RequiredMappingStrategy.cs b/src/Riok.Mapperly.Abstractions/RequiredMappingStrategy.cs index 03ca613592..81f8d24223 100644 --- a/src/Riok.Mapperly.Abstractions/RequiredMappingStrategy.cs +++ b/src/Riok.Mapperly.Abstractions/RequiredMappingStrategy.cs @@ -24,5 +24,5 @@ public enum RequiredMappingStrategy /// /// Warnings are emitted for unmapped target members but not for source members. /// - Target = 1 << 1 + Target = 1 << 1, } diff --git a/src/Riok.Mapperly/Configuration/AttributeDataAccessor.cs b/src/Riok.Mapperly/Configuration/AttributeDataAccessor.cs index 53475715eb..5b0f96cb80 100644 --- a/src/Riok.Mapperly/Configuration/AttributeDataAccessor.cs +++ b/src/Riok.Mapperly/Configuration/AttributeDataAccessor.cs @@ -129,18 +129,19 @@ IReadOnlyList argumentSyntax { return arg.Kind switch { - _ when (targetType == typeof(AttributeValue?) || targetType == typeof(AttributeValue)) && syntax != null - => new AttributeValue(arg, syntax.Expression), + _ when (targetType == typeof(AttributeValue?) || targetType == typeof(AttributeValue)) && syntax != null => new AttributeValue( + arg, + syntax.Expression + ), _ when arg.IsNull => null, _ when targetType == typeof(StringMemberPath) => CreateMemberPath(arg, syntax), TypedConstantKind.Enum => GetEnumValue(arg, targetType), TypedConstantKind.Array => BuildArrayValue(arg, targetType), TypedConstantKind.Primitive => arg.Value, TypedConstantKind.Type when targetType == typeof(ITypeSymbol) => arg.Value, - _ - => throw new ArgumentOutOfRangeException( - $"{nameof(AttributeDataAccessor)} does not support constructor arguments of kind {arg.Kind.ToString()} or cannot convert it to {targetType}" - ), + _ => throw new ArgumentOutOfRangeException( + $"{nameof(AttributeDataAccessor)} does not support constructor arguments of kind {arg.Kind.ToString()} or cannot convert it to {targetType}" + ), }; } diff --git a/src/Riok.Mapperly/Configuration/MembersMappingConfiguration.cs b/src/Riok.Mapperly/Configuration/MembersMappingConfiguration.cs index e8e533e73a..d5123fa664 100644 --- a/src/Riok.Mapperly/Configuration/MembersMappingConfiguration.cs +++ b/src/Riok.Mapperly/Configuration/MembersMappingConfiguration.cs @@ -18,8 +18,9 @@ public IEnumerable GetMembersWithExplicitConfigurations(MappingSourceTar var members = sourceTarget switch { MappingSourceTarget.Source => ExplicitMappings.Where(x => x.Source.Path.Count > 0).Select(x => x.Source.Path[0]), - MappingSourceTarget.Target - => ExplicitMappings.Select(x => x.Target.Path[0]).Concat(ValueMappings.Select(x => x.Target.Path[0])), + MappingSourceTarget.Target => ExplicitMappings + .Select(x => x.Target.Path[0]) + .Concat(ValueMappings.Select(x => x.Target.Path[0])), _ => throw new ArgumentOutOfRangeException(nameof(sourceTarget), sourceTarget, "Neither source or target"), }; return members.Distinct(); diff --git a/src/Riok.Mapperly/Descriptors/Enumerables/CollectionInfoBuilder.cs b/src/Riok.Mapperly/Descriptors/Enumerables/CollectionInfoBuilder.cs index 7eb634a27a..8f065462c0 100644 --- a/src/Riok.Mapperly/Descriptors/Enumerables/CollectionInfoBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/Enumerables/CollectionInfoBuilder.cs @@ -30,8 +30,8 @@ private readonly record struct CollectionTypeInfo( private static readonly CollectionTypeInfo _collectionTypeInfoArray = new(CollectionType.Array); - private static readonly IReadOnlyCollection _collectionTypeInfos = new[] - { + private static readonly IReadOnlyCollection _collectionTypeInfos = + [ new CollectionTypeInfo(CollectionType.IEnumerable, typeof(IEnumerable<>)), new CollectionTypeInfo(CollectionType.List, typeof(List<>), nameof(List.Add)), new CollectionTypeInfo(CollectionType.Stack, typeof(Stack<>), nameof(Stack.Push)), @@ -64,7 +64,7 @@ private readonly record struct CollectionTypeInfo( new CollectionTypeInfo(CollectionType.ReadOnlySpan, typeof(ReadOnlySpan<>)), new CollectionTypeInfo(CollectionType.Memory, typeof(Memory<>)), new CollectionTypeInfo(CollectionType.ReadOnlyMemory, typeof(ReadOnlyMemory<>)), - }; + ]; private static readonly IReadOnlyDictionary _collectionClrTypeByType = _collectionTypeInfos .Where(x => x.ReflectionType != null) @@ -267,128 +267,115 @@ private static CollectionType GetImplementedCollectionTypes(WellKnownTypes types // when collectionType is None then manually check for implemented types with IterateImplementedTypes return collectionType switch { - CollectionType.Array - => CollectionType.Array - | CollectionType.IList - | CollectionType.IReadOnlyList - | CollectionType.ICollection - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, + CollectionType.Array => CollectionType.Array + | CollectionType.IList + | CollectionType.IReadOnlyList + | CollectionType.ICollection + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, CollectionType.IEnumerable => CollectionType.IEnumerable, - CollectionType.List - => CollectionType.List - | CollectionType.IList - | CollectionType.IReadOnlyList - | CollectionType.ICollection - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, + CollectionType.List => CollectionType.List + | CollectionType.IList + | CollectionType.IReadOnlyList + | CollectionType.ICollection + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, CollectionType.Stack => CollectionType.Stack | CollectionType.IReadOnlyCollection | CollectionType.IEnumerable, CollectionType.Queue => CollectionType.Queue | CollectionType.IReadOnlyCollection | CollectionType.IEnumerable, CollectionType.IReadOnlyCollection => CollectionType.IReadOnlyCollection | CollectionType.IEnumerable, CollectionType.IList => CollectionType.IList | CollectionType.ICollection | CollectionType.IEnumerable, CollectionType.IReadOnlyList => CollectionType.IReadOnlyList | CollectionType.IReadOnlyCollection | CollectionType.IEnumerable, CollectionType.ICollection => CollectionType.ICollection | CollectionType.IEnumerable, - CollectionType.HashSet - => CollectionType.HashSet - | CollectionType.ISet - | CollectionType.IReadOnlySet - | CollectionType.ICollection - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, - CollectionType.SortedSet - => CollectionType.SortedSet - | CollectionType.ISet - | CollectionType.IReadOnlySet - | CollectionType.ICollection - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, + CollectionType.HashSet => CollectionType.HashSet + | CollectionType.ISet + | CollectionType.IReadOnlySet + | CollectionType.ICollection + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, + CollectionType.SortedSet => CollectionType.SortedSet + | CollectionType.ISet + | CollectionType.IReadOnlySet + | CollectionType.ICollection + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, CollectionType.ISet => CollectionType.ISet | CollectionType.ICollection | CollectionType.IEnumerable, CollectionType.IReadOnlySet => CollectionType.IReadOnlySet | CollectionType.IReadOnlyCollection | CollectionType.IEnumerable, CollectionType.IDictionary => CollectionType.IDictionary | CollectionType.ICollection | CollectionType.IEnumerable, - CollectionType.IReadOnlyDictionary - => CollectionType.IReadOnlyDictionary | CollectionType.IReadOnlyCollection | CollectionType.IEnumerable, - CollectionType.Dictionary - => CollectionType.Dictionary - | CollectionType.IDictionary - | CollectionType.IReadOnlyDictionary - | CollectionType.ICollection - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, - - CollectionType.ImmutableArray - => CollectionType.ImmutableArray - | CollectionType.IImmutableList - | CollectionType.IList - | CollectionType.IReadOnlyList - | CollectionType.ICollection - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, - CollectionType.ImmutableList - => CollectionType.ImmutableList - | CollectionType.IImmutableList - | CollectionType.IList - | CollectionType.IReadOnlyList - | CollectionType.ICollection - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, - CollectionType.IImmutableList - => CollectionType.IImmutableList - | CollectionType.IReadOnlyList - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, - CollectionType.ImmutableHashSet - => CollectionType.ImmutableHashSet - | CollectionType.IImmutableSet - | CollectionType.IReadOnlySet - | CollectionType.ISet - | CollectionType.ICollection - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, + CollectionType.IReadOnlyDictionary => CollectionType.IReadOnlyDictionary + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, + CollectionType.Dictionary => CollectionType.Dictionary + | CollectionType.IDictionary + | CollectionType.IReadOnlyDictionary + | CollectionType.ICollection + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, + + CollectionType.ImmutableArray => CollectionType.ImmutableArray + | CollectionType.IImmutableList + | CollectionType.IList + | CollectionType.IReadOnlyList + | CollectionType.ICollection + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, + CollectionType.ImmutableList => CollectionType.ImmutableList + | CollectionType.IImmutableList + | CollectionType.IList + | CollectionType.IReadOnlyList + | CollectionType.ICollection + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, + CollectionType.IImmutableList => CollectionType.IImmutableList + | CollectionType.IReadOnlyList + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, + CollectionType.ImmutableHashSet => CollectionType.ImmutableHashSet + | CollectionType.IImmutableSet + | CollectionType.IReadOnlySet + | CollectionType.ISet + | CollectionType.ICollection + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, CollectionType.IImmutableSet => CollectionType.IImmutableSet | CollectionType.IReadOnlyCollection | CollectionType.IEnumerable, - CollectionType.ImmutableSortedSet - => CollectionType.ImmutableSortedSet - | CollectionType.IImmutableSet - | CollectionType.IList - | CollectionType.IReadOnlyList - | CollectionType.ISet - | CollectionType.IReadOnlySet - | CollectionType.ICollection - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, + CollectionType.ImmutableSortedSet => CollectionType.ImmutableSortedSet + | CollectionType.IImmutableSet + | CollectionType.IList + | CollectionType.IReadOnlyList + | CollectionType.ISet + | CollectionType.IReadOnlySet + | CollectionType.ICollection + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, CollectionType.ImmutableQueue => CollectionType.ImmutableQueue | CollectionType.IImmutableQueue | CollectionType.IEnumerable, CollectionType.IImmutableQueue => CollectionType.IImmutableQueue | CollectionType.IEnumerable, CollectionType.ImmutableStack => CollectionType.ImmutableStack | CollectionType.IImmutableStack | CollectionType.IEnumerable, CollectionType.IImmutableStack => CollectionType.IImmutableStack | CollectionType.IEnumerable, - CollectionType.ImmutableDictionary - => CollectionType.ImmutableDictionary - | CollectionType.IImmutableDictionary - | CollectionType.IDictionary - | CollectionType.IReadOnlyDictionary - | CollectionType.ICollection - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, - CollectionType.IImmutableDictionary - => CollectionType.IImmutableDictionary - | CollectionType.IReadOnlyDictionary - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, - CollectionType.ImmutableSortedDictionary - => CollectionType.ImmutableSortedDictionary - | CollectionType.IImmutableDictionary - | CollectionType.IReadOnlyDictionary - | CollectionType.IReadOnlyCollection - | CollectionType.IEnumerable, + CollectionType.ImmutableDictionary => CollectionType.ImmutableDictionary + | CollectionType.IImmutableDictionary + | CollectionType.IDictionary + | CollectionType.IReadOnlyDictionary + | CollectionType.ICollection + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, + CollectionType.IImmutableDictionary => CollectionType.IImmutableDictionary + | CollectionType.IReadOnlyDictionary + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, + CollectionType.ImmutableSortedDictionary => CollectionType.ImmutableSortedDictionary + | CollectionType.IImmutableDictionary + | CollectionType.IReadOnlyDictionary + | CollectionType.IReadOnlyCollection + | CollectionType.IEnumerable, CollectionType.Span => CollectionType.Span, CollectionType.ReadOnlySpan => CollectionType.ReadOnlySpan, CollectionType.Memory => CollectionType.Memory, CollectionType.ReadOnlyMemory => CollectionType.ReadOnlyMemory, // check for if the type is a string, returning IEnumerable - CollectionType.None when type.SpecialType == SpecialType.System_String - => CollectionType.IEnumerable, + CollectionType.None when type.SpecialType == SpecialType.System_String => CollectionType.IEnumerable, // fallback for CollectionType.None, manually checking for known implemented types - _ => IterateImplementedTypes(type, types) + _ => IterateImplementedTypes(type, types), }; static CollectionType IterateImplementedTypes(ITypeSymbol type, WellKnownTypes types) diff --git a/src/Riok.Mapperly/Descriptors/ExternalMappings/ExternalMappingsExtractor.cs b/src/Riok.Mapperly/Descriptors/ExternalMappings/ExternalMappingsExtractor.cs index 944816ff53..3c8ac8efad 100644 --- a/src/Riok.Mapperly/Descriptors/ExternalMappings/ExternalMappingsExtractor.cs +++ b/src/Riok.Mapperly/Descriptors/ExternalMappings/ExternalMappingsExtractor.cs @@ -42,12 +42,12 @@ private static IEnumerable ValidateAndExtractExternalInstanceMappi }; if (type == null) - return Enumerable.Empty(); + return []; if (nullableAnnotation != NullableAnnotation.Annotated) return UserMethodMappingExtractor.ExtractUserImplementedMappings(ctx, type, name, isStatic: false, isExternal: true); ctx.ReportDiagnostic(DiagnosticDescriptors.ExternalMapperMemberCannotBeNullable, symbol, symbol.ToDisplayString()); - return Enumerable.Empty(); + return []; } } diff --git a/src/Riok.Mapperly/Descriptors/InlineExpressionMappingBuilderContext.cs b/src/Riok.Mapperly/Descriptors/InlineExpressionMappingBuilderContext.cs index a1daaf5c15..27ea19c012 100644 --- a/src/Riok.Mapperly/Descriptors/InlineExpressionMappingBuilderContext.cs +++ b/src/Riok.Mapperly/Descriptors/InlineExpressionMappingBuilderContext.cs @@ -203,17 +203,16 @@ private INewInstanceMapping TryInlineMapping(INewInstanceMapping mapping) return mapping switch { // inline existing mapping - UserImplementedMethodMapping implementedMapping - => InlineExpressionMappingBuilder.TryBuildMapping(this, implementedMapping) ?? implementedMapping, + UserImplementedMethodMapping implementedMapping => InlineExpressionMappingBuilder.TryBuildMapping(this, implementedMapping) + ?? implementedMapping, // build an inlined version - IUserMapping userMapping - => BuildMapping( - userMapping, - new TypeMappingKey(userMapping), - MappingBuildingOptions.Default, - userMapping.Method.GetSyntaxLocation() - ) ?? mapping, + IUserMapping userMapping => BuildMapping( + userMapping, + new TypeMappingKey(userMapping), + MappingBuildingOptions.Default, + userMapping.Method.GetSyntaxLocation() + ) ?? mapping, _ => mapping, }; diff --git a/src/Riok.Mapperly/Descriptors/MapperDescriptor.cs b/src/Riok.Mapperly/Descriptors/MapperDescriptor.cs index 2345b3bb54..a7b4efbff2 100644 --- a/src/Riok.Mapperly/Descriptors/MapperDescriptor.cs +++ b/src/Riok.Mapperly/Descriptors/MapperDescriptor.cs @@ -13,8 +13,8 @@ public class MapperDescriptor private const string AccessorClassName = "UnsafeAccessor"; private readonly MapperDeclaration _declaration; - private readonly List _methodMappings = new(); - private readonly List _unsafeAccessors = new(); + private readonly List _methodMappings = []; + private readonly List _unsafeAccessors = []; public bool Static { get; set; } diff --git a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersContainerBuilderContext.cs b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersContainerBuilderContext.cs index adcedc768a..6894c8fbbb 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersContainerBuilderContext.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersContainerBuilderContext.cs @@ -15,7 +15,7 @@ public class MembersContainerBuilderContext(MappingBuilderContext builderCont where T : IMemberAssignmentTypeMapping { private readonly Dictionary _nullDelegateMappings = new(); - private readonly HashSet _initializedNullableTargetPaths = new(); + private readonly HashSet _initializedNullableTargetPaths = []; public void AddMemberAssignmentMapping(IMemberAssignmentMapping memberMapping) => AddMemberAssignmentMapping(Mapping, memberMapping); diff --git a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/MemberMappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/MemberMappingBuilder.cs index 98fa7bb172..ba88b1e63d 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/MemberMappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/MemberMappingBuilder.cs @@ -18,7 +18,7 @@ internal static class MemberMappingBuilder public enum CodeStyle { Expression, - Statement + Statement, } public static bool TryBuildContainerAssignment( diff --git a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewInstanceObjectMemberMappingBodyBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewInstanceObjectMemberMappingBodyBuilder.cs index 448051a7af..d97d208288 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewInstanceObjectMemberMappingBodyBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewInstanceObjectMemberMappingBodyBuilder.cs @@ -152,7 +152,7 @@ private static bool TryBuildConstructorMapping( [NotNullWhen(true)] out List? constructorParameterMappings ) { - constructorParameterMappings = new List(); + constructorParameterMappings = []; var skippedOptionalParam = false; foreach (var parameter in ctor.Parameters) diff --git a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewValueTupleMappingBodyBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewValueTupleMappingBodyBuilder.cs index 300bb6740d..269b045924 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewValueTupleMappingBodyBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewValueTupleMappingBodyBuilder.cs @@ -47,7 +47,7 @@ private static bool TryBuildTupleConstructorMapping( out List constructorParameterMappings ) { - constructorParameterMappings = new List(); + constructorParameterMappings = []; var targetMembers = ctx.EnumerateUnmappedTargetMembers().ToList(); diff --git a/src/Riok.Mapperly/Descriptors/MappingBuilders/DictionaryMappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBuilders/DictionaryMappingBuilder.cs index 5929e3abb3..ece07b76f0 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBuilders/DictionaryMappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBuilders/DictionaryMappingBuilder.cs @@ -217,11 +217,20 @@ INewInstanceMapping valueMapping { return ctx.CollectionInfos!.Target.CollectionType switch { - CollectionType.ImmutableSortedDictionary - => new LinqDictionaryMapping(ctx.Source, ctx.Target, ToImmutableSortedDictionaryMethodName, keyMapping, valueMapping), - CollectionType.ImmutableDictionary - or CollectionType.IImmutableDictionary - => new LinqDictionaryMapping(ctx.Source, ctx.Target, ToImmutableDictionaryMethodName, keyMapping, valueMapping), + CollectionType.ImmutableSortedDictionary => new LinqDictionaryMapping( + ctx.Source, + ctx.Target, + ToImmutableSortedDictionaryMethodName, + keyMapping, + valueMapping + ), + CollectionType.ImmutableDictionary or CollectionType.IImmutableDictionary => new LinqDictionaryMapping( + ctx.Source, + ctx.Target, + ToImmutableDictionaryMethodName, + keyMapping, + valueMapping + ), _ => null, }; @@ -236,11 +245,10 @@ private static CollectionInfo BuildCollectionTypeForSourceIDictionary(MappingBui if (ctx.HasUserSymbol) return info; - CollectionType? dictionaryType = info.ImplementedTypes.HasFlag(CollectionType.IReadOnlyDictionary) - ? CollectionType.IReadOnlyDictionary - : info.ImplementedTypes.HasFlag(CollectionType.IDictionary) - ? CollectionType.IDictionary - : null; + CollectionType? dictionaryType = + info.ImplementedTypes.HasFlag(CollectionType.IReadOnlyDictionary) ? CollectionType.IReadOnlyDictionary + : info.ImplementedTypes.HasFlag(CollectionType.IDictionary) ? CollectionType.IDictionary + : null; return dictionaryType == null ? info diff --git a/src/Riok.Mapperly/Descriptors/MappingBuilders/EnumMappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBuilders/EnumMappingBuilder.cs index b81f0fcfe0..437852ddd8 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBuilders/EnumMappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBuilders/EnumMappingBuilder.cs @@ -35,8 +35,8 @@ public static class EnumMappingBuilder return ctx.Configuration.Enum.Strategy switch { EnumMappingStrategy.ByName when ctx.IsExpression => BuildCastMappingAndDiagnostic(ctx), - EnumMappingStrategy.ByValue when ctx is { IsExpression: true, Configuration.Enum.HasExplicitConfigurations: true } - => BuildCastMappingAndDiagnostic(ctx), + EnumMappingStrategy.ByValue when ctx is { IsExpression: true, Configuration.Enum.HasExplicitConfigurations: true } => + BuildCastMappingAndDiagnostic(ctx), EnumMappingStrategy.ByValueCheckDefined when ctx.IsExpression => BuildCastMappingAndDiagnostic(ctx), EnumMappingStrategy.ByName => BuildNameMapping(ctx), EnumMappingStrategy.ByValueCheckDefined => BuildEnumToEnumCastMapping(ctx, checkTargetDefined: true), diff --git a/src/Riok.Mapperly/Descriptors/MappingBuilders/EnumerableMappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBuilders/EnumerableMappingBuilder.cs index a516579377..05a3f4da90 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBuilders/EnumerableMappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBuilders/EnumerableMappingBuilder.cs @@ -374,7 +374,7 @@ or CollectionType.ICollection CollectionType.ImmutableQueue or CollectionType.IImmutableQueue => CreateRangeQueueMethodName, CollectionType.ImmutableStack or CollectionType.IImmutableStack => CreateRangeStackMethodName, CollectionType.ImmutableSortedSet => ToImmutableSortedSetMethodName, - _ => null + _ => null, }; } @@ -388,11 +388,10 @@ private static CollectionInfo BuildCollectionTypeForICollection(MappingBuilderCo if (ctx.HasUserSymbol) return info; - CollectionType? collectionType = info.ImplementedTypes.HasFlag(CollectionType.IReadOnlyCollection) - ? CollectionType.IReadOnlyCollection - : info.ImplementedTypes.HasFlag(CollectionType.ICollection) - ? CollectionType.ICollection - : null; + CollectionType? collectionType = + info.ImplementedTypes.HasFlag(CollectionType.IReadOnlyCollection) ? CollectionType.IReadOnlyCollection + : info.ImplementedTypes.HasFlag(CollectionType.ICollection) ? CollectionType.ICollection + : null; return collectionType == null ? info : CollectionInfoBuilder.BuildGenericCollectionInfo(ctx, collectionType.Value, info); } diff --git a/src/Riok.Mapperly/Descriptors/MappingBuilders/ExistingTargetMappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBuilders/ExistingTargetMappingBuilder.cs index 7b9ccdb045..4b12db02a8 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBuilders/ExistingTargetMappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBuilders/ExistingTargetMappingBuilder.cs @@ -14,7 +14,7 @@ public class ExistingTargetMappingBuilder(MappingCollection mappings) SpanMappingBuilder.TryBuildExistingTargetMapping, MemoryMappingBuilder.TryBuildExistingTargetMapping, EnumerableMappingBuilder.TryBuildExistingTargetMapping, - NewInstanceObjectMemberMappingBuilder.TryBuildExistingTargetMapping + NewInstanceObjectMemberMappingBuilder.TryBuildExistingTargetMapping, ]; public IExistingTargetMapping? Find(TypeMappingKey mappingKey) diff --git a/src/Riok.Mapperly/Descriptors/MappingBuilders/InlineExpressionMappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBuilders/InlineExpressionMappingBuilder.cs index 51c0b5c84e..c3995aa722 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBuilders/InlineExpressionMappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBuilders/InlineExpressionMappingBuilder.cs @@ -73,12 +73,11 @@ public static class InlineExpressionMappingBuilder { Declaration.Variables: [{ Initializer: { } variableInitializer } variableDeclarator] }, - ReturnStatementSyntax { Expression: IdentifierNameSyntax identifierName } + ReturnStatementSyntax { Expression: IdentifierNameSyntax identifierName }, ] - } when identifierName.Identifier.Value == variableDeclarator.Identifier.Value - => variableInitializer.Value, + } when identifierName.Identifier.Value == variableDeclarator.Identifier.Value => variableInitializer.Value, - _ => null + _ => null, }; } } diff --git a/src/Riok.Mapperly/Descriptors/MappingBuilders/MappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBuilders/MappingBuilder.cs index 0bba301161..a9a098fcb6 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBuilders/MappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBuilders/MappingBuilder.cs @@ -5,7 +5,7 @@ namespace Riok.Mapperly.Descriptors.MappingBuilders; public class MappingBuilder(MappingCollection mappings, MapperDeclaration mapperDeclaration) { - private readonly HashSet _resolvedMappingNames = new(); + private readonly HashSet _resolvedMappingNames = []; private delegate INewInstanceMapping? BuildMapping(MappingBuilderContext context); @@ -31,7 +31,7 @@ public class MappingBuilder(MappingCollection mappings, MapperDeclaration mapper DateTimeToTimeOnlyMappingBuilder.TryBuildMapping, ExplicitCastMappingBuilder.TryBuildMapping, ToStringMappingBuilder.TryBuildMapping, - NewInstanceObjectMemberMappingBuilder.TryBuildMapping + NewInstanceObjectMemberMappingBuilder.TryBuildMapping, ]; /// diff --git a/src/Riok.Mapperly/Descriptors/MappingBuilders/NewInstanceObjectMemberMappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBuilders/NewInstanceObjectMemberMappingBuilder.cs index d09cac866b..7d31c0312f 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBuilders/NewInstanceObjectMemberMappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBuilders/NewInstanceObjectMemberMappingBuilder.cs @@ -25,7 +25,7 @@ public static class NewInstanceObjectMemberMappingBuilder ctx.Configuration.Mapper.UseReferenceHandling ) { - Constructor = constructor + Constructor = constructor, }; } diff --git a/src/Riok.Mapperly/Descriptors/MappingBuilders/SpanMappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBuilders/SpanMappingBuilder.cs index 3568d04f04..ea8a73e06d 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBuilders/SpanMappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBuilders/SpanMappingBuilder.cs @@ -44,8 +44,7 @@ public static class SpanMappingBuilder // if the source is Span/ReadOnlySpan or Array and target is Span/ReadOnlySpan // and element type is the same, then direct cast (CollectionType.Span or CollectionType.ReadOnlySpan or CollectionType.Array, CollectionType.Span or CollectionType.ReadOnlySpan) - when elementMapping.IsSynthetic && !ctx.Configuration.Mapper.UseDeepCloning - => new CastMapping(ctx.Source, ctx.Target), + when elementMapping.IsSynthetic && !ctx.Configuration.Mapper.UseDeepCloning => new CastMapping(ctx.Source, ctx.Target), // otherwise map each value into an Array _ => BuildToArrayOrMap(ctx, elementMapping), diff --git a/src/Riok.Mapperly/Descriptors/MappingBuilders/ToStringMappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBuilders/ToStringMappingBuilder.cs index 8428f01f00..6d209fc2dd 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBuilders/ToStringMappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBuilders/ToStringMappingBuilder.cs @@ -24,27 +24,45 @@ public static class ToStringMappingBuilder return (stringFormat, formatProvider, formatProviderIsDefault) switch { // ToString(string, IFormatProvider) - (not null, not null, _) when HasToStringMethod(ctx, true, true) - => new ToStringMapping(ctx.Source, ctx.Target, stringFormat, formatProvider.Name), + (not null, not null, _) when HasToStringMethod(ctx, true, true) => new ToStringMapping( + ctx.Source, + ctx.Target, + stringFormat, + formatProvider.Name + ), // ToString(string) - (not null, not null, true) when HasToStringMethod(ctx, true, false) - => new ToStringMapping(ctx.Source, ctx.Target, stringFormat), + (not null, not null, true) when HasToStringMethod(ctx, true, false) => new ToStringMapping( + ctx.Source, + ctx.Target, + stringFormat + ), // ToString(string) (not null, null, _) when HasToStringMethod(ctx, true, false) => new ToStringMapping(ctx.Source, ctx.Target, stringFormat), // ToString(string, null) - (not null, null, _) when HasToStringMethodWithNullableParameter(ctx, 1) - => new ToStringMapping(ctx.Source, ctx.Target, stringFormat, simpleInvocation: false), + (not null, null, _) when HasToStringMethodWithNullableParameter(ctx, 1) => new ToStringMapping( + ctx.Source, + ctx.Target, + stringFormat, + simpleInvocation: false + ), // ToString(IFormatProvider) - (null, not null, _) when HasToStringMethod(ctx, false, true) - => new ToStringMapping(ctx.Source, ctx.Target, formatProviderName: formatProvider.Name), + (null, not null, _) when HasToStringMethod(ctx, false, true) => new ToStringMapping( + ctx.Source, + ctx.Target, + formatProviderName: formatProvider.Name + ), // ToString(null, IFormatProvider) - (null, not null, _) when HasToStringMethodWithNullableParameter(ctx, 0) - => new ToStringMapping(ctx.Source, ctx.Target, formatProviderName: formatProvider.Name, simpleInvocation: false), + (null, not null, _) when HasToStringMethodWithNullableParameter(ctx, 0) => new ToStringMapping( + ctx.Source, + ctx.Target, + formatProviderName: formatProvider.Name, + simpleInvocation: false + ), // ToString() (null, not null, true) => new ToStringMapping(ctx.Source, ctx.Target), @@ -90,14 +108,12 @@ is not { return (stringFormatParam, formatProviderParam) switch { - (true, true) - => method.Parameters.Length == 2 - && method.Parameters[0].Type.SpecialType == SpecialType.System_String - && SymbolEqualityComparer.Default.Equals(method.Parameters[1].Type, ctx.Types.Get()), + (true, true) => method.Parameters.Length == 2 + && method.Parameters[0].Type.SpecialType == SpecialType.System_String + && SymbolEqualityComparer.Default.Equals(method.Parameters[1].Type, ctx.Types.Get()), (true, false) => method.Parameters is [{ Type.SpecialType: SpecialType.System_String }], - (false, true) - => method.Parameters.Length == 1 - && SymbolEqualityComparer.Default.Equals(method.Parameters[0].Type, ctx.Types.Get()), + (false, true) => method.Parameters.Length == 1 + && SymbolEqualityComparer.Default.Equals(method.Parameters[0].Type, ctx.Types.Get()), _ => false, }; } diff --git a/src/Riok.Mapperly/Descriptors/MappingCollection.cs b/src/Riok.Mapperly/Descriptors/MappingCollection.cs index 11f9bcadb1..05cb0a2f26 100644 --- a/src/Riok.Mapperly/Descriptors/MappingCollection.cs +++ b/src/Riok.Mapperly/Descriptors/MappingCollection.cs @@ -15,7 +15,7 @@ public class MappingCollection /// to keep track of the registration order and generate the members in the same order as they are registered /// (the user defined order). /// - private readonly List _methodMappings = new(); + private readonly List _methodMappings = []; /// /// A list of all user mappings. @@ -24,7 +24,7 @@ public class MappingCollection /// This is kept outside of /// to keep track of the registration order and generate the members in the same order as they are registered. /// - private readonly List _userMappings = new(); + private readonly List _userMappings = []; /// /// Queue of mappings which don't have the body built yet @@ -80,11 +80,17 @@ public MappingCollectionAddResult AddUserMapping(IUserMapping userMapping, strin return userMapping switch { - INewInstanceUserMapping newInstanceMapping - => _newInstanceMappings.AddUserMapping(newInstanceMapping, userMapping.Default, name), - IExistingTargetUserMapping existingTargetMapping - => _existingTargetMappings.AddUserMapping(existingTargetMapping, userMapping.Default, name), - _ => throw new ArgumentOutOfRangeException(nameof(userMapping), userMapping.GetType().FullName + " mappings are not supported") + INewInstanceUserMapping newInstanceMapping => _newInstanceMappings.AddUserMapping( + newInstanceMapping, + userMapping.Default, + name + ), + IExistingTargetUserMapping existingTargetMapping => _existingTargetMappings.AddUserMapping( + existingTargetMapping, + userMapping.Default, + name + ), + _ => throw new ArgumentOutOfRangeException(nameof(userMapping), userMapping.GetType().FullName + " mappings are not supported"), }; } @@ -149,12 +155,12 @@ private class MappingCollectionInstance /// /// Duplicated mapping names. /// - private readonly HashSet _duplicatedMappingNames = new(); + private readonly HashSet _duplicatedMappingNames = []; /// /// All mapping type keys which for which an explicit default mapping is configured. /// - private readonly HashSet _explicitDefaultMappingKeys = new(); + private readonly HashSet _explicitDefaultMappingKeys = []; /// /// Contains the duplicated user implemented mappings @@ -165,12 +171,12 @@ private class MappingCollectionInstance /// /// All mapping keys for which was called and returned a non-null result. /// - private readonly HashSet _usedMappingKeys = new(); + private readonly HashSet _usedMappingKeys = []; /// /// All mappings for which was called and returned a non-null result. /// - private readonly HashSet _referencedNamedMappings = new(); + private readonly HashSet _referencedNamedMappings = []; /// public IReadOnlyDictionary DefaultMappings => _defaultMappings; @@ -249,7 +255,7 @@ public MappingCollectionAddResult AddUserMapping(TUserMapping mapping, bool? isD // no default value specified // add it if none exists yet - null => TryAddUserMappingAsDefault(mapping) + null => TryAddUserMappingAsDefault(mapping), }; } diff --git a/src/Riok.Mapperly/Descriptors/Mappings/Enums/EnumCastMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/Enums/EnumCastMapping.cs index b6a1a9042a..4ab5439dff 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/Enums/EnumCastMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/Enums/EnumCastMapping.cs @@ -32,7 +32,7 @@ public enum CheckDefinedMode /// /// It is checked if the casted value is a defined flags combination of the target enum. /// - Flags + Flags, } public override ExpressionSyntax Build(TypeMappingBuildContext ctx) @@ -51,16 +51,14 @@ private ExpressionSyntax BuildIsDefinedCondition(ExpressionSyntax convertedSourc return checkDefinedMode switch { // (TargetEnum)v is TargetEnum.A or TargetEnum.B or ... - CheckDefinedMode.Value - => IsPattern(convertedSourceValue, OrPattern(allEnumMembers)), + CheckDefinedMode.Value => IsPattern(convertedSourceValue, OrPattern(allEnumMembers)), // (TargetEnum)v == ((TargetEnum)v & (TargetEnum.A | TargetEnum.B | ...)) - CheckDefinedMode.Flags - => Equal( - convertedSourceValue, - ParenthesizedExpression(BitwiseAnd(convertedSourceValue, ParenthesizedExpression(BitwiseOr(allEnumMembers)))) - ), - _ => throw new ArgumentOutOfRangeException($"{nameof(checkDefinedMode)} has an unknown value {checkDefinedMode}") + CheckDefinedMode.Flags => Equal( + convertedSourceValue, + ParenthesizedExpression(BitwiseAnd(convertedSourceValue, ParenthesizedExpression(BitwiseOr(allEnumMembers)))) + ), + _ => throw new ArgumentOutOfRangeException($"{nameof(checkDefinedMode)} has an unknown value {checkDefinedMode}"), }; } } diff --git a/src/Riok.Mapperly/Descriptors/Mappings/Enums/EnumFromStringParseMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/Enums/EnumFromStringParseMapping.cs index b9a466cc4a..5b5080369e 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/Enums/EnumFromStringParseMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/Enums/EnumFromStringParseMapping.cs @@ -25,7 +25,7 @@ public override ExpressionSyntax Build(TypeMappingBuildContext ctx) return ctx.SyntaxFactory.GenericInvocation( EnumClassName, ParseMethodName, - new[] { FullyQualifiedIdentifier(TargetType) }, + [FullyQualifiedIdentifier(TargetType)], ctx.Source, BooleanLiteral(ignoreCase) ); diff --git a/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs index 66662831fb..2721148593 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/ExistingTarget/NullDelegateExistingTargetMapping.cs @@ -26,13 +26,11 @@ public override IEnumerable Build(TypeMappingBuildContext ctx, // if body is empty don't generate an if statement if (body.Length == 0) - { - return Enumerable.Empty(); - } + return []; // if (source != null && target != null) { body } var condition = IfNoneNull((SourceType, ctx.Source), (TargetType, target)); var ifStatement = ctx.SyntaxFactory.If(condition, body); - return new[] { ifStatement }; + return [ifStatement]; } } diff --git a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs index 923e9f6e46..d16fcb016d 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs @@ -7,9 +7,9 @@ namespace Riok.Mapperly.Descriptors.Mappings.MemberMappings; /// public abstract class MemberAssignmentMappingContainer(IMemberAssignmentMappingContainer? parent = null) : IMemberAssignmentMappingContainer { - private readonly HashSet _delegateMappings = new(); - private readonly HashSet _childContainers = new(); - private readonly List _mappings = new(); + private readonly HashSet _delegateMappings = []; + private readonly HashSet _childContainers = []; + private readonly List _mappings = []; public virtual IEnumerable Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) => _mappings.SelectMany(x => x.Build(ctx, targetAccess)); diff --git a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberNullDelegateAssignmentMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberNullDelegateAssignmentMapping.cs index cd6aa956a1..51adc2d6ec 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberNullDelegateAssignmentMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberNullDelegateAssignmentMapping.cs @@ -16,7 +16,7 @@ bool needsNullSafeAccess ) : MemberAssignmentMappingContainer(parent) { private readonly MemberPathGetter _nullConditionalSourcePath = nullConditionalSourcePath; - private readonly List _targetsToSetNull = new(); + private readonly List _targetsToSetNull = []; private bool _throwOnSourcePathNull; public void ThrowOnSourcePathNull() @@ -41,7 +41,7 @@ public override IEnumerable Build(TypeMappingBuildContext ctx, var trueClause = base.Build(conditionCtx, targetAccess); var elseClause = BuildElseClause(conditionCtx, targetAccess); var ifExpression = ctx.SyntaxFactory.If(condition, trueClause, elseClause); - return new[] { ifExpression }; + return [ifExpression]; } public void AddNullMemberAssignment(MemberPathSetter targetPath) => _targetsToSetNull.Add(targetPath); diff --git a/src/Riok.Mapperly/Descriptors/Mappings/MethodMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/MethodMapping.cs index 6403a1aaeb..b8a3604dfd 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/MethodMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/MethodMapping.cs @@ -23,13 +23,13 @@ public abstract class MethodMapping : ITypeMapping private const int SourceParameterIndex = 0; private const int ReferenceHandlerParameterIndex = 1; - private static readonly IEnumerable _privateSyntaxToken = new[] { TrailingSpacedToken(SyntaxKind.PrivateKeyword) }; + private static readonly IEnumerable _privateSyntaxToken = [TrailingSpacedToken(SyntaxKind.PrivateKeyword)]; - private static readonly IEnumerable _privateStaticSyntaxToken = new[] - { + private static readonly IEnumerable _privateStaticSyntaxToken = + [ TrailingSpacedToken(SyntaxKind.PrivateKeyword), TrailingSpacedToken(SyntaxKind.StaticKeyword), - }; + ]; private readonly ITypeSymbol _returnType; private readonly MethodDeclarationSyntax? _methodDeclarationSyntax; diff --git a/src/Riok.Mapperly/Descriptors/Mappings/NewInstanceObjectMemberMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/NewInstanceObjectMemberMapping.cs index 67c7ff82da..58aa3dd334 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/NewInstanceObjectMemberMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/NewInstanceObjectMemberMapping.cs @@ -15,8 +15,8 @@ public class NewInstanceObjectMemberMapping(ITypeSymbol sourceType, ITypeSymbol INewInstanceObjectMemberMapping { private IInstanceConstructor? _constructor; - private readonly HashSet _constructorMemberMappings = new(); - private readonly HashSet _initMemberMappings = new(); + private readonly HashSet _constructorMemberMappings = []; + private readonly HashSet _initMemberMappings = []; public IInstanceConstructor Constructor { diff --git a/src/Riok.Mapperly/Descriptors/Mappings/NewInstanceObjectMemberMethodMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/NewInstanceObjectMemberMethodMapping.cs index a635550ff8..e149252817 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/NewInstanceObjectMemberMethodMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/NewInstanceObjectMemberMethodMapping.cs @@ -17,8 +17,8 @@ public class NewInstanceObjectMemberMethodMapping(ITypeSymbol sourceType, ITypeS private const string TargetVariableName = "target"; private IInstanceConstructor? _constructor; - private readonly HashSet _constructorMemberMappings = new(); - private readonly HashSet _initMemberMappings = new(); + private readonly HashSet _constructorMemberMappings = []; + private readonly HashSet _initMemberMappings = []; public IInstanceConstructor Constructor { diff --git a/src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleConstructorMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleConstructorMapping.cs index 608f5082a2..c9a20a089e 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleConstructorMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleConstructorMapping.cs @@ -15,7 +15,7 @@ public class NewValueTupleConstructorMapping(ITypeSymbol sourceType, ITypeSymbol INewValueTupleMapping { private const string ValueTupleName = "global::System.ValueTuple"; - private readonly HashSet _constructorPropertyMappings = new(); + private readonly HashSet _constructorPropertyMappings = []; public void AddConstructorParameterMapping(ValueTupleConstructorParameterMapping mapping) => _constructorPropertyMappings.Add(mapping); diff --git a/src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleExpressionMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleExpressionMapping.cs index 6372d11b52..1ad13c467b 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleExpressionMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleExpressionMapping.cs @@ -16,7 +16,7 @@ public class NewValueTupleExpressionMapping(ITypeSymbol sourceType, ITypeSymbol INewValueTupleMapping { private const string TargetVariableName = "target"; - private readonly HashSet _constructorPropertyMappings = new(); + private readonly HashSet _constructorPropertyMappings = []; public void AddConstructorParameterMapping(ValueTupleConstructorParameterMapping mapping) => _constructorPropertyMappings.Add(mapping); diff --git a/src/Riok.Mapperly/Descriptors/Mappings/SourceObjectMethodMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/SourceObjectMethodMapping.cs index cf858943d6..be734fa496 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/SourceObjectMethodMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/SourceObjectMethodMapping.cs @@ -29,5 +29,5 @@ public override ExpressionSyntax Build(TypeMappingBuildContext ctx) return delegateMapping == null ? sourceExpression : delegateMapping.Build(ctx.WithSource(sourceExpression)); } - protected virtual IEnumerable BuildArguments(TypeMappingBuildContext ctx) => Enumerable.Empty(); + protected virtual IEnumerable BuildArguments(TypeMappingBuildContext ctx) => []; } diff --git a/src/Riok.Mapperly/Descriptors/Mappings/ToStringMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/ToStringMapping.cs index d20b6efe2f..0b57982a69 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/ToStringMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/ToStringMapping.cs @@ -25,15 +25,11 @@ public class ToStringMapping( { protected override IEnumerable BuildArguments(TypeMappingBuildContext ctx) { - yield return stringFormat != null - ? StringLiteral(stringFormat) - : simpleInvocation - ? null - : NullLiteral(); - yield return formatProviderName != null - ? IdentifierName(formatProviderName) - : simpleInvocation - ? null - : NullLiteral(); + yield return stringFormat != null ? StringLiteral(stringFormat) + : simpleInvocation ? null + : NullLiteral(); + yield return formatProviderName != null ? IdentifierName(formatProviderName) + : simpleInvocation ? null + : NullLiteral(); } } diff --git a/src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserDefinedNewInstanceRuntimeTargetTypeMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserDefinedNewInstanceRuntimeTargetTypeMapping.cs index 6d1bd5f9cd..a9837969b8 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserDefinedNewInstanceRuntimeTargetTypeMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserDefinedNewInstanceRuntimeTargetTypeMapping.cs @@ -26,7 +26,7 @@ ITypeSymbol objectType private const string IsAssignableFromMethodName = nameof(Type.IsAssignableFrom); private const string GetTypeMethodName = nameof(GetType); - private readonly List _mappings = new(); + private readonly List _mappings = []; public new IMethodSymbol Method { get; } = method; diff --git a/src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedInlinedExpressionMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedInlinedExpressionMapping.cs index 6e54214687..e5a5d24756 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedInlinedExpressionMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedInlinedExpressionMapping.cs @@ -60,9 +60,9 @@ private IEnumerable ExtractOverwrittenIdentifiers(SyntaxNode node) { return node switch { - SimpleLambdaExpressionSyntax simpleLambda => new[] { simpleLambda.Parameter.Identifier }, + SimpleLambdaExpressionSyntax simpleLambda => [simpleLambda.Parameter.Identifier], ParenthesizedLambdaExpressionSyntax lambda => lambda.ParameterList.Parameters.Select(p => p.Identifier), - _ => Enumerable.Empty() + _ => [], }; } } diff --git a/src/Riok.Mapperly/Descriptors/SymbolAccessor.cs b/src/Riok.Mapperly/Descriptors/SymbolAccessor.cs index 3b0598867c..56fce1d9a0 100644 --- a/src/Riok.Mapperly/Descriptors/SymbolAccessor.cs +++ b/src/Riok.Mapperly/Descriptors/SymbolAccessor.cs @@ -70,12 +70,12 @@ private bool IsAccessible(ISymbol symbol, MemberVisibility visibility) return symbol.DeclaredAccessibility switch { Accessibility.Private => visibility.HasFlag(MemberVisibility.Private), - Accessibility.ProtectedAndInternal - => visibility.HasFlag(MemberVisibility.Protected) && visibility.HasFlag(MemberVisibility.Internal), + Accessibility.ProtectedAndInternal => visibility.HasFlag(MemberVisibility.Protected) + && visibility.HasFlag(MemberVisibility.Internal), Accessibility.Protected => visibility.HasFlag(MemberVisibility.Protected), Accessibility.Internal => visibility.HasFlag(MemberVisibility.Internal), - Accessibility.ProtectedOrInternal - => visibility.HasFlag(MemberVisibility.Protected) || visibility.HasFlag(MemberVisibility.Internal), + Accessibility.ProtectedOrInternal => visibility.HasFlag(MemberVisibility.Protected) + || visibility.HasFlag(MemberVisibility.Internal), Accessibility.Public => visibility.HasFlag(MemberVisibility.Public), _ => false, }; diff --git a/src/Riok.Mapperly/Descriptors/UnsafeAccess/UnsafeAccessorContext.cs b/src/Riok.Mapperly/Descriptors/UnsafeAccess/UnsafeAccessorContext.cs index e9a2e71664..9d03936423 100644 --- a/src/Riok.Mapperly/Descriptors/UnsafeAccess/UnsafeAccessorContext.cs +++ b/src/Riok.Mapperly/Descriptors/UnsafeAccess/UnsafeAccessorContext.cs @@ -8,7 +8,7 @@ namespace Riok.Mapperly.Descriptors.UnsafeAccess; public class UnsafeAccessorContext(UniqueNameBuilder nameBuilder, SymbolAccessor symbolAccessor, string className) { - private readonly List _unsafeAccessors = new(); + private readonly List _unsafeAccessors = []; private readonly Dictionary _unsafeAccessorsBySymbol = new(); private readonly UniqueNameBuilder _nameBuilder = nameBuilder.NewScope(); @@ -63,7 +63,7 @@ Func factory UnsafeAccessorType.GetProperty or UnsafeAccessorType.GetField => BuildExtensionMethodName("Get", symbol), UnsafeAccessorType.SetProperty => BuildExtensionMethodName("Set", symbol), UnsafeAccessorType.Constructor => _nameBuilder.New("Create" + symbol.ContainingType.Name), - _ => throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown type") + _ => throw new ArgumentOutOfRangeException(nameof(type), type, "Unknown type"), }; return CacheAccessor(key, factory(symbol, className, methodName)); } diff --git a/src/Riok.Mapperly/Descriptors/UserMethodMappingExtractor.cs b/src/Riok.Mapperly/Descriptors/UserMethodMappingExtractor.cs index 20ac67874e..b5b8994a70 100644 --- a/src/Riok.Mapperly/Descriptors/UserMethodMappingExtractor.cs +++ b/src/Riok.Mapperly/Descriptors/UserMethodMappingExtractor.cs @@ -277,11 +277,9 @@ IMethodSymbol methodSymbol // for the source type we assume a nullable by default var targetCanBeNull = targetType is ITypeParameterSymbol tpsTarget ? tpsTarget.IsNullable() ?? false : targetType.IsNullable(); var sourceCanBeNull = sourceType is ITypeParameterSymbol tpsSource ? tpsSource.IsNullable() ?? true : sourceType.IsNullable(); - return !sourceCanBeNull - ? null - : targetCanBeNull - ? NullFallbackValue.Default - : NullFallbackValue.ThrowArgumentNullException; + return !sourceCanBeNull ? null + : targetCanBeNull ? NullFallbackValue.Default + : NullFallbackValue.ThrowArgumentNullException; } private static UserMappingConfiguration GetUserMappingConfig( diff --git a/src/Riok.Mapperly/Diagnostics/DiagnosticCollection.cs b/src/Riok.Mapperly/Diagnostics/DiagnosticCollection.cs index 2aac750542..405acc81db 100644 --- a/src/Riok.Mapperly/Diagnostics/DiagnosticCollection.cs +++ b/src/Riok.Mapperly/Diagnostics/DiagnosticCollection.cs @@ -6,7 +6,7 @@ namespace Riok.Mapperly.Diagnostics; public class DiagnosticCollection(Location defaultLocation) : IReadOnlyCollection { - private readonly List _diagnostics = new(); + private readonly List _diagnostics = []; public IEnumerator GetEnumerator() => _diagnostics.GetEnumerator(); diff --git a/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.Literal.cs b/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.Literal.cs index 16eb67a3d0..445aff0f6d 100644 --- a/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.Literal.cs +++ b/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.Literal.cs @@ -55,7 +55,7 @@ public static LiteralExpressionSyntax Literal(object? obj) decimal d => DecimalLiteral(d), double d => DoubleLiteral(d), float f => FloatLiteral(f), - _ => throw new ArgumentOutOfRangeException(nameof(obj), obj, "Unsupported literal type " + obj.GetType()) + _ => throw new ArgumentOutOfRangeException(nameof(obj), obj, "Unsupported literal type " + obj.GetType()), }; } } diff --git a/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.Null.cs b/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.Null.cs index 3a65a571aa..8a96647f80 100644 --- a/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.Null.cs +++ b/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.Null.cs @@ -37,15 +37,15 @@ NullFallbackValue.Default when t.IsNullableValueType() => DefaultExpression(Full NullFallbackValue.Default => DefaultLiteral(), NullFallbackValue.EmptyString => StringLiteral(string.Empty), NullFallbackValue.CreateInstance => CreateInstance(t), - _ when argument is ElementAccessExpressionSyntax memberAccess - => ThrowNullReferenceException( - InterpolatedString( - $"Sequence {NameOf(memberAccess.Expression)}, contained a null value at index {memberAccess.ArgumentList.Arguments[0].Expression}." - ) - ), + _ when argument is ElementAccessExpressionSyntax memberAccess => ThrowNullReferenceException( + InterpolatedString( + $"Sequence {NameOf(memberAccess.Expression)}, contained a null value at index {memberAccess.ArgumentList.Arguments[0].Expression}." + ) + ), _ when argument is MemberAccessExpressionSyntax or SimpleNameSyntax => ThrowArgumentNullException(argument), - _ when argument is InvocationExpressionSyntax invocation - => ThrowNullReferenceException(StringLiteral(invocation.Expression + " returned null")), + _ when argument is InvocationExpressionSyntax invocation => ThrowNullReferenceException( + StringLiteral(invocation.Expression + " returned null") + ), _ => ThrowNullReferenceException(StringLiteral(argument + " is null")), }; } diff --git a/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.SymbolDeclaration.cs b/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.SymbolDeclaration.cs index fbd95538c7..3b45aca5d1 100644 --- a/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.SymbolDeclaration.cs +++ b/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.SymbolDeclaration.cs @@ -25,7 +25,7 @@ public ClassDeclarationSyntax Class(string name, SyntaxTokenList modifiers, Synt .WithKeyword(TrailingSpacedToken(SyntaxKind.ClassKeyword)) .WithOpenBraceToken(LeadingLineFeedToken(SyntaxKind.OpenBraceToken)) .WithCloseBraceToken(LeadingLineFeedToken(SyntaxKind.CloseBraceToken)) - .WithAttributeLists(isPartial ? new SyntaxList() : GeneratedCodeAttributeList()) + .WithAttributeLists(isPartial ? [] : GeneratedCodeAttributeList()) .AddLeadingLineFeed(Indentation); } @@ -38,7 +38,7 @@ public TypeDeclarationSyntax TypeDeclaration(TypeDeclarationSyntax syntax, Synta StructDeclarationSyntax => StructDeclaration(name), InterfaceDeclarationSyntax => InterfaceDeclaration(name), RecordDeclarationSyntax => RecordDeclaration(Token(SyntaxKind.RecordKeyword), name), - _ => throw new NotSupportedException($"Unsupported type declaration syntax {syntax.GetType().Name}.") + _ => throw new NotSupportedException($"Unsupported type declaration syntax {syntax.GetType().Name}."), }; var isPartial = syntax.Modifiers.Any(kind => kind.IsKind(SyntaxKind.PartialKeyword)); @@ -48,7 +48,7 @@ public TypeDeclarationSyntax TypeDeclaration(TypeDeclarationSyntax syntax, Synta .WithKeyword(TrailingSpacedToken(syntax.Keyword.Kind())) .WithOpenBraceToken(LeadingLineFeedToken(SyntaxKind.OpenBraceToken)) .WithCloseBraceToken(LeadingLineFeedToken(SyntaxKind.CloseBraceToken)) - .WithAttributeLists(isPartial ? new SyntaxList() : GeneratedCodeAttributeList()) + .WithAttributeLists(isPartial ? [] : GeneratedCodeAttributeList()) .AddLeadingLineFeed(Indentation); } } diff --git a/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.cs b/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.cs index 868efcb972..6c3639b836 100644 --- a/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.cs +++ b/src/Riok.Mapperly/Emit/Syntax/SyntaxFactoryHelper.cs @@ -43,14 +43,12 @@ public BlockSyntax Block(IEnumerable statements) private StatementSyntax BlockIfNotReturnOrThrow(StatementSyntax statement) { - return statement.IsKind(SyntaxKind.ReturnStatement) || statement.IsKind(SyntaxKind.ThrowStatement) - ? statement - : Block(new[] { statement }); + return statement.IsKind(SyntaxKind.ReturnStatement) || statement.IsKind(SyntaxKind.ThrowStatement) ? statement : Block([statement]); } private BlockSyntax Block(IEnumerable statements) => Block(statements.Select(AddIndentation().ExpressionStatement)); - public IReadOnlyCollection SingleStatement(ExpressionSyntax expression) => new[] { ExpressionStatement(expression) }; + public IReadOnlyCollection SingleStatement(ExpressionSyntax expression) => [ExpressionStatement(expression)]; public ExpressionStatementSyntax ExpressionStatement(ExpressionSyntax expression) => SyntaxFactory.ExpressionStatement(expression).AddLeadingLineFeed(Indentation); diff --git a/src/Riok.Mapperly/Helpers/MethodNameBuilder.cs b/src/Riok.Mapperly/Helpers/MethodNameBuilder.cs index 858e691b11..9bb41ab503 100644 --- a/src/Riok.Mapperly/Helpers/MethodNameBuilder.cs +++ b/src/Riok.Mapperly/Helpers/MethodNameBuilder.cs @@ -23,13 +23,13 @@ private string BuildTypeMethodName(ITypeSymbol t) return t switch { IArrayTypeSymbol arrType => BuildTypeMethodName(arrType.ElementType) + ArrayTypeNameSuffix, - INamedTypeSymbol { TypeArguments.Length: 1 } genericT - => genericT.Name + GenericTypeNameSeparator + genericT.TypeArguments[0].Name, - INamedTypeSymbol { TypeArguments.Length: > 1 } genericT - => genericT.Name - + GenericTypeNameSeparator - + string.Join(TypeArgumentSeparator, genericT.TypeArguments.Take(MaxTypeArguments).Select(static x => x.Name)), - _ => t.Name + INamedTypeSymbol { TypeArguments.Length: 1 } genericT => genericT.Name + + GenericTypeNameSeparator + + genericT.TypeArguments[0].Name, + INamedTypeSymbol { TypeArguments.Length: > 1 } genericT => genericT.Name + + GenericTypeNameSeparator + + string.Join(TypeArgumentSeparator, genericT.TypeArguments.Take(MaxTypeArguments).Select(static x => x.Name)), + _ => t.Name, }; } } diff --git a/src/Riok.Mapperly/Helpers/NullableSymbolExtensions.cs b/src/Riok.Mapperly/Helpers/NullableSymbolExtensions.cs index ad1111ce05..b79e6384ed 100644 --- a/src/Riok.Mapperly/Helpers/NullableSymbolExtensions.cs +++ b/src/Riok.Mapperly/Helpers/NullableSymbolExtensions.cs @@ -105,7 +105,7 @@ internal static bool IsNullableUpgraded(this ITypeSymbol symbol) { INamedTypeSymbol namedTypeSymbol when namedTypeSymbol.TypeArguments.Any(x => !x.IsNullableUpgraded()) => false, IArrayTypeSymbol arrayTypeSymbol when !arrayTypeSymbol.ElementType.IsNullableUpgraded() => false, - _ => true + _ => true, }; } diff --git a/test/Riok.Mapperly.Abstractions.Tests/MapPropertyAttributeTest.cs b/test/Riok.Mapperly.Abstractions.Tests/MapPropertyAttributeTest.cs index 471ce32531..3f602ea417 100644 --- a/test/Riok.Mapperly.Abstractions.Tests/MapPropertyAttributeTest.cs +++ b/test/Riok.Mapperly.Abstractions.Tests/MapPropertyAttributeTest.cs @@ -6,9 +6,9 @@ public class MapPropertyAttributeTest public void ShouldSplitMemberAccess() { var attr = new MapPropertyAttribute("a.b.c", "d.e.f"); - attr.Source.Should().BeEquivalentTo(new[] { "a", "b", "c" }, o => o.WithStrictOrdering()); + attr.Source.Should().BeEquivalentTo(["a", "b", "c"], o => o.WithStrictOrdering()); attr.SourceFullName.Should().Be("a.b.c"); - attr.Target.Should().BeEquivalentTo(new[] { "d", "e", "f" }, o => o.WithStrictOrdering()); + attr.Target.Should().BeEquivalentTo(["d", "e", "f"], o => o.WithStrictOrdering()); attr.TargetFullName.Should().Be("d.e.f"); } } diff --git a/test/Riok.Mapperly.IntegrationTests/BaseMapperTest.cs b/test/Riok.Mapperly.IntegrationTests/BaseMapperTest.cs index cfd24d556b..2fa31df72f 100644 --- a/test/Riok.Mapperly.IntegrationTests/BaseMapperTest.cs +++ b/test/Riok.Mapperly.IntegrationTests/BaseMapperTest.cs @@ -80,9 +80,9 @@ public static TestObject NewTestObj() FlagsEnumValue = TestFlagsEnum.V1 | TestFlagsEnum.V4, IntInitOnlyValue = 3, RequiredValue = 4, - NestedNullable = new TestObjectNested { IntValue = 100, }, + NestedNullable = new TestObjectNested { IntValue = 100 }, StringValue = "fooBar", - SubObject = new InheritanceSubObject { BaseIntValue = 1, SubIntValue = 2, }, + SubObject = new InheritanceSubObject { BaseIntValue = 1, SubIntValue = 2 }, EnumRawValue = TestEnum.Value20, EnumStringValue = TestEnum.Value30, DateTimeValue = new DateTime(2020, 1, 3, 15, 10, 5, DateTimeKind.Utc), @@ -100,7 +100,7 @@ public static TestObject NewTestObj() NestedMember = new() { NestedMemberId = 12, - NestedMemberObject = new() { IntValue = 22 } + NestedMemberObject = new() { IntValue = 22 }, }, TupleValue = ("10", "20"), RecursiveObject = new(5) @@ -122,8 +122,8 @@ public static TestObject NewTestObj() NestedMember = new() { NestedMemberId = 123, - NestedMemberObject = new() { IntValue = 223 } - } + NestedMemberObject = new() { IntValue = 223 }, + }, }, MemoryValue = new[] { "1", "2", "3" }, StackValue = new Stack(new[] { "1", "2", "3" }), @@ -138,26 +138,26 @@ public static TestObject NewTestObj() { { "1", "1" }, { "2", "2" }, - { "3", "3" } + { "3", "3" }, }.ToImmutableDictionary(), ImmutableSortedDictionaryValue = new Dictionary() { { "1", "1" }, { "2", "2" }, - { "3", "3" } + { "3", "3" }, }.ToImmutableSortedDictionary(), - ExistingISet = { "1", "2", "3", }, - ExistingHashSet = { "1", "2", "3", }, - ExistingSortedSet = { "1", "2", "3", }, - ExistingList = { "1", "2", "3", }, - ISet = new HashSet { "1", "2", "3", }, + ExistingISet = { "1", "2", "3" }, + ExistingHashSet = { "1", "2", "3" }, + ExistingSortedSet = { "1", "2", "3" }, + ExistingList = { "1", "2", "3" }, + ISet = new HashSet { "1", "2", "3" }, #if NET5_0_OR_GREATER - IReadOnlySet = new HashSet { "1", "2", "3", }, + IReadOnlySet = new HashSet { "1", "2", "3" }, #endif - HashSet = new HashSet { "1", "2", "3", }, - SortedSet = new SortedSet { "1", "2", "3", }, + HashSet = new HashSet { "1", "2", "3" }, + SortedSet = new SortedSet { "1", "2", "3" }, SumComponent1 = 32, - SumComponent2 = 64 + SumComponent2 = 64, }; } diff --git a/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoByName.cs b/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoByName.cs index 16d0fdb9c2..efbbce57fe 100644 --- a/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoByName.cs +++ b/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoByName.cs @@ -4,6 +4,6 @@ public enum TestEnumDtoByName { Value10 = 10_000, Value20 = 20_000, - Value30 = 30_000 + Value30 = 30_000, } } diff --git a/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoByValue.cs b/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoByValue.cs index 928f047722..895b083a95 100644 --- a/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoByValue.cs +++ b/test/Riok.Mapperly.IntegrationTests/Dto/TestEnumDtoByValue.cs @@ -4,6 +4,6 @@ public enum TestEnumDtoByValue { DtoValue1 = 10, DtoValue2 = 20, - DtoValue3 = 30 + DtoValue3 = 30, } } diff --git a/test/Riok.Mapperly.IntegrationTests/ProjectionMapperTest.cs b/test/Riok.Mapperly.IntegrationTests/ProjectionMapperTest.cs index 3c5f31b60a..ca3be5f97e 100644 --- a/test/Riok.Mapperly.IntegrationTests/ProjectionMapperTest.cs +++ b/test/Riok.Mapperly.IntegrationTests/ProjectionMapperTest.cs @@ -105,7 +105,7 @@ private TestObjectProjection CreateObject() StringValue = "fooBar3", IgnoredStringValue = "fooBar4", NullableFlattening = new IdObject { IdValue = 20 }, - SubObject = new InheritanceSubObject { BaseIntValue = 10, SubIntValue = 20, }, + SubObject = new InheritanceSubObject { BaseIntValue = 10, SubIntValue = 20 }, RecursiveObject = new TestObjectProjection { RequiredValue = -1, diff --git a/test/Riok.Mapperly.IntegrationTests/StaticMapperTest.cs b/test/Riok.Mapperly.IntegrationTests/StaticMapperTest.cs index fd3ed1d792..ed4aae6016 100644 --- a/test/Riok.Mapperly.IntegrationTests/StaticMapperTest.cs +++ b/test/Riok.Mapperly.IntegrationTests/StaticMapperTest.cs @@ -46,13 +46,13 @@ public void NestedListsShouldWork() { new() { - new() { "1", "2", "3" } + new() { "1", "2", "3" }, }, new() { new() { "4", "5" }, - new() { "6" } - } + new() { "6" }, + }, }; var mapped = StaticTestMapper.MapNestedLists(l); diff --git a/test/Riok.Mapperly.Tests/Descriptors/MemberPathCandidateBuilderTest.cs b/test/Riok.Mapperly.Tests/Descriptors/MemberPathCandidateBuilderTest.cs index 4d4de58bf4..e4a889ce7d 100644 --- a/test/Riok.Mapperly.Tests/Descriptors/MemberPathCandidateBuilderTest.cs +++ b/test/Riok.Mapperly.Tests/Descriptors/MemberPathCandidateBuilderTest.cs @@ -24,7 +24,7 @@ public class MemberPathCandidateBuilderTest "MyValueId.Num", "My.ValueId.Num", "MyValue.Id.Num", - "My.Value.Id.Num" + "My.Value.Id.Num", } )] public void BuildMemberPathCandidatesShouldWork(string name, string[] chunks) diff --git a/test/Riok.Mapperly.Tests/Helpers/DictionaryExtensionsTest.cs b/test/Riok.Mapperly.Tests/Helpers/DictionaryExtensionsTest.cs index d550d51211..d670be7cdd 100644 --- a/test/Riok.Mapperly.Tests/Helpers/DictionaryExtensionsTest.cs +++ b/test/Riok.Mapperly.Tests/Helpers/DictionaryExtensionsTest.cs @@ -9,7 +9,7 @@ public class DictionaryExtensionsTest [Fact] public void RemoveShouldReturnTrueWhenKeyWasRemoved() { - var d = new Dictionary { ["a"] = 10, ["b"] = 20, }; + var d = new Dictionary { ["a"] = 10, ["b"] = 20 }; DictionaryExtensions.Remove(d, "a", out var value).Should().BeTrue(); value.Should().Be(10); } @@ -17,7 +17,7 @@ public void RemoveShouldReturnTrueWhenKeyWasRemoved() [Fact] public void RemoveShouldReturnFalseWhenKeyWasNotRemoved() { - var d = new Dictionary { ["a"] = 10, ["b"] = 20, }; + var d = new Dictionary { ["a"] = 10, ["b"] = 20 }; DictionaryExtensions.Remove(d, "c", out var value).Should().BeFalse(); value.Should().Be(0); } @@ -29,16 +29,16 @@ public void RemoveRangeShouldRemoveEntries() { ["a"] = 10, ["b"] = 20, - ["c"] = 30 + ["c"] = 30, }; - d.RemoveRange(new[] { "a", "c" }); + d.RemoveRange(["a", "c"]); d.Keys.Should().BeEquivalentTo("b"); } [Fact] public void TryAddShouldNotAddExistingKey() { - var d = new Dictionary { ["a"] = 10, }; + var d = new Dictionary { ["a"] = 10 }; d.TryAdd("a", 20).Should().BeFalse(); @@ -48,7 +48,7 @@ public void TryAddShouldNotAddExistingKey() [Fact] public void TryAddShouldAddNewKey() { - var d = new Dictionary { ["a"] = 10, }; + var d = new Dictionary { ["a"] = 10 }; d.TryAdd("b", 20).Should().BeTrue(); diff --git a/test/Riok.Mapperly.Tests/Helpers/EnumerableExtensionsTest.cs b/test/Riok.Mapperly.Tests/Helpers/EnumerableExtensionsTest.cs index f29a036d7a..8dddcfc6d4 100644 --- a/test/Riok.Mapperly.Tests/Helpers/EnumerableExtensionsTest.cs +++ b/test/Riok.Mapperly.Tests/Helpers/EnumerableExtensionsTest.cs @@ -10,7 +10,7 @@ public void WhereValueTypeNotNullShouldFilterNulls() new int?[] { 1, null, null, 2, 3, 4, null } .WhereNotNull() .Should() - .BeEquivalentTo(new[] { 1, 2, 3, 4 }, o => o.WithStrictOrdering()); + .BeEquivalentTo([1, 2, 3, 4], o => o.WithStrictOrdering()); } [Fact] @@ -19,7 +19,7 @@ public void WhereNotNullShouldFilterNulls() new[] { "a", "b", "c", null, "d", null, null, "e" } .WhereNotNull() .Should() - .BeEquivalentTo(new[] { "a", "b", "c", "d", "e" }, o => o.WithStrictOrdering()); + .BeEquivalentTo(["a", "b", "c", "d", "e"], o => o.WithStrictOrdering()); } [Fact] diff --git a/test/Riok.Mapperly.Tests/Helpers/GenericTypeCheckerTest.cs b/test/Riok.Mapperly.Tests/Helpers/GenericTypeCheckerTest.cs index 9980565567..6c87f10bf7 100644 --- a/test/Riok.Mapperly.Tests/Helpers/GenericTypeCheckerTest.cs +++ b/test/Riok.Mapperly.Tests/Helpers/GenericTypeCheckerTest.cs @@ -271,7 +271,7 @@ public class Mapper {{types}} """ ); - var compilation = TestHelper.BuildCompilation(source, TestHelperOptions.Default with { NullableOption = nullableOptions, }); + var compilation = TestHelper.BuildCompilation(source, TestHelperOptions.Default with { NullableOption = nullableOptions }); var nodes = compilation.SyntaxTrees.Single().GetRoot().DescendantNodes(); var classNode = nodes.OfType().Single(x => x.Identifier.Text == "Mapper"); var methodNode = nodes.OfType().Single(x => x.Identifier.Text == "Test"); @@ -295,7 +295,7 @@ public class Mapper ); var targetMethodTypeSymbol = methodSymbol.ReturnsVoid ? methodSymbol.Parameters[1].Type : methodSymbol.ReturnType; - parametersAndArguments = [(methodSymbol.Parameters[0].Type, sourceSymbol), (targetMethodTypeSymbol, targetSymbol),]; + parametersAndArguments = [(methodSymbol.Parameters[0].Type, sourceSymbol), (targetMethodTypeSymbol, targetSymbol)]; } return typeChecker.InferAndCheckTypes(methodSymbol.TypeParameters, parametersAndArguments); diff --git a/test/Riok.Mapperly.Tests/Helpers/HashSetExtensionsTest.cs b/test/Riok.Mapperly.Tests/Helpers/HashSetExtensionsTest.cs index 0e1562e54f..0397ee5d13 100644 --- a/test/Riok.Mapperly.Tests/Helpers/HashSetExtensionsTest.cs +++ b/test/Riok.Mapperly.Tests/Helpers/HashSetExtensionsTest.cs @@ -8,7 +8,7 @@ public class HashSetExtensionsTest public void AddRangeShouldAddAllItems() { var h = new HashSet { 1, 2, 3 }; - h.AddRange(new[] { 3, 4, 5, 5 }); - h.Should().Contain(new[] { 1, 2, 3, 4, 5 }); + h.AddRange([3, 4, 5, 5]); + h.Should().Contain([1, 2, 3, 4, 5]); } } diff --git a/test/Riok.Mapperly.Tests/Helpers/ListDictionaryTests.cs b/test/Riok.Mapperly.Tests/Helpers/ListDictionaryTests.cs index 896420d5c9..390c0cbec4 100644 --- a/test/Riok.Mapperly.Tests/Helpers/ListDictionaryTests.cs +++ b/test/Riok.Mapperly.Tests/Helpers/ListDictionaryTests.cs @@ -9,12 +9,12 @@ public void AddAndGetOrEmptyShouldAddValueAndReturn() { var l = new ListDictionary(); l.Add(1, 1); - l.GetOrEmpty(1).Should().BeEquivalentTo(new[] { 1 }, x => x.WithStrictOrdering()); + l.GetOrEmpty(1).Should().BeEquivalentTo([1], x => x.WithStrictOrdering()); l.Add(1, 2); - l.GetOrEmpty(1).Should().BeEquivalentTo(new[] { 1, 2 }, x => x.WithStrictOrdering()); + l.GetOrEmpty(1).Should().BeEquivalentTo([1, 2], x => x.WithStrictOrdering()); l.Add(2, 3); - l.GetOrEmpty(1).Should().BeEquivalentTo(new[] { 1, 2 }, x => x.WithStrictOrdering()); - l.GetOrEmpty(2).Should().BeEquivalentTo(new[] { 3 }, x => x.WithStrictOrdering()); + l.GetOrEmpty(1).Should().BeEquivalentTo([1, 2], x => x.WithStrictOrdering()); + l.GetOrEmpty(2).Should().BeEquivalentTo([3], x => x.WithStrictOrdering()); } [Fact] diff --git a/test/Riok.Mapperly.Tests/Helpers/MethodNameBuilderTest.cs b/test/Riok.Mapperly.Tests/Helpers/MethodNameBuilderTest.cs index fad3cdb1b7..994024ed21 100644 --- a/test/Riok.Mapperly.Tests/Helpers/MethodNameBuilderTest.cs +++ b/test/Riok.Mapperly.Tests/Helpers/MethodNameBuilderTest.cs @@ -33,6 +33,6 @@ private class MockedMethodMapping : MethodMapping public MockedMethodMapping(ITypeSymbol t) : base(t, t) { } - public override IEnumerable BuildBody(TypeMappingBuildContext ctx) => Enumerable.Empty(); + public override IEnumerable BuildBody(TypeMappingBuildContext ctx) => []; } } diff --git a/test/Riok.Mapperly.Tests/MapperGenerationResultAssertions.cs b/test/Riok.Mapperly.Tests/MapperGenerationResultAssertions.cs index 0e208241f6..9f203f3779 100644 --- a/test/Riok.Mapperly.Tests/MapperGenerationResultAssertions.cs +++ b/test/Riok.Mapperly.Tests/MapperGenerationResultAssertions.cs @@ -13,7 +13,7 @@ public class MapperGenerationResultAssertions public MapperGenerationResultAssertions(MapperGenerationResult mapper) { _mapper = mapper; - _notAssertedDiagnostics = new HashSet(_mapper.Diagnostics); + _notAssertedDiagnostics = [.. _mapper.Diagnostics]; } public MapperGenerationResultAssertions HaveDiagnostics() diff --git a/test/Riok.Mapperly.Tests/Mapping/DictionaryTest.cs b/test/Riok.Mapperly.Tests/Mapping/DictionaryTest.cs index bccfcd8881..0dc336f513 100644 --- a/test/Riok.Mapperly.Tests/Mapping/DictionaryTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/DictionaryTest.cs @@ -94,7 +94,7 @@ public void DictionaryToDictionaryNullableToNonNullableWithNoThrow() "Dictionary", TestSourceBuilderOptions.Default with { - ThrowOnMappingNullMismatch = false + ThrowOnMappingNullMismatch = false, } ); TestHelper diff --git a/test/Riok.Mapperly.Tests/Mapping/EnumTest.cs b/test/Riok.Mapperly.Tests/Mapping/EnumTest.cs index 96ee357edb..4961995def 100644 --- a/test/Riok.Mapperly.Tests/Mapping/EnumTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/EnumTest.cs @@ -201,7 +201,7 @@ public void EnumToOtherEnumByNameViaGlobalConfigShouldSwitch() "E2", TestSourceBuilderOptions.Default with { - EnumMappingStrategy = EnumMappingStrategy.ByName + EnumMappingStrategy = EnumMappingStrategy.ByName, }, "enum E1 {A, B, C}", "enum E2 {A = 100, B, C}" @@ -430,7 +430,7 @@ string targetEnumValues "B", TestSourceBuilderOptions.Default with { - EnumMappingStrategy = enumMappingStrategy + EnumMappingStrategy = enumMappingStrategy, }, "class A { public C Value { get; set; } }", "class B { public D Value { get; set; } }", @@ -456,7 +456,7 @@ public Task EnumToAnotherEnumByNameCaseInsensitive(string testCase, string sourc TestSourceBuilderOptions.Default with { EnumMappingStrategy = EnumMappingStrategy.ByName, - EnumMappingIgnoreCase = true + EnumMappingIgnoreCase = true, }, "class A { public C Value { get; set; } }", "class B { public D Value { get; set; } }", diff --git a/test/Riok.Mapperly.Tests/Mapping/NullableTest.cs b/test/Riok.Mapperly.Tests/Mapping/NullableTest.cs index 771af9822b..143835b81b 100644 --- a/test/Riok.Mapperly.Tests/Mapping/NullableTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/NullableTest.cs @@ -69,7 +69,7 @@ public void NullableToNonNullableWithNoThrowShouldReturnNewInstance() "B", TestSourceBuilderOptions.Default with { - ThrowOnMappingNullMismatch = false + ThrowOnMappingNullMismatch = false, }, "class A { }", "class B { }" @@ -96,7 +96,7 @@ public Task NullableToNonNullableWithNoThrowNoAccessibleCtorShouldDiagnostic() "B", TestSourceBuilderOptions.Default with { - ThrowOnMappingNullMismatch = false + ThrowOnMappingNullMismatch = false, }, "class B { protected B(){} public static B Parse(string v) => new B(); }" ); @@ -111,7 +111,7 @@ public void NullableToNonNullableStringWithNoThrowShouldReturnEmptyString() "string", TestSourceBuilderOptions.Default with { - ThrowOnMappingNullMismatch = false + ThrowOnMappingNullMismatch = false, }, "class A { }" ); @@ -127,7 +127,7 @@ public void NullableToNonNullableValueTypeWithNoThrowShouldReturnDefault() "DateTime", TestSourceBuilderOptions.Default with { - ThrowOnMappingNullMismatch = false + ThrowOnMappingNullMismatch = false, } ); diff --git a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyConstructorResolverTest.cs b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyConstructorResolverTest.cs index 9e60cdae9a..1ad242331b 100644 --- a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyConstructorResolverTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyConstructorResolverTest.cs @@ -386,7 +386,7 @@ public void RecordToFlattenedRecordNullablePathNoThrow() "B", TestSourceBuilderOptions.Default with { - ThrowOnMappingNullMismatch = false + ThrowOnMappingNullMismatch = false, }, "record A(C? Nested);", "record B(string NestedValue);", diff --git a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyInitPropertyTest.cs b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyInitPropertyTest.cs index 0b7af9e93f..a8583a0dce 100644 --- a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyInitPropertyTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyInitPropertyTest.cs @@ -86,7 +86,7 @@ public void InitOnlyPropertyWithNullableSourceNoThrow() "B", TestSourceBuilderOptions.Default with { - ThrowOnMappingNullMismatch = false + ThrowOnMappingNullMismatch = false, }, "class A { public string? Value { get; init; } }", "class B { public string Value { get; init; } }" diff --git a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyNullableTest.cs b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyNullableTest.cs index 6ce00ae5b1..742260b7a1 100644 --- a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyNullableTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyNullableTest.cs @@ -59,7 +59,7 @@ public void NullableIntToNonNullableIntPropertyWithNoNullAssignment() "B", TestSourceBuilderOptions.Default with { - AllowNullPropertyAssignment = false + AllowNullPropertyAssignment = false, }, "class A { public int? Value { get; set; } }", "class B { public int Value { get; set; } }" @@ -89,7 +89,7 @@ public void NullableIntToNonNullableIntPropertyWithNoNullAssignmentThrow() TestSourceBuilderOptions.Default with { AllowNullPropertyAssignment = false, - ThrowOnPropertyMappingNullMismatch = true + ThrowOnPropertyMappingNullMismatch = true, }, "class A { public int? Value { get; set; } }", "class B { public int Value { get; set; } }" @@ -196,7 +196,7 @@ public void NullableStringToNullableStringPropertyWithNoNullAssignment() "B", TestSourceBuilderOptions.Default with { - AllowNullPropertyAssignment = false + AllowNullPropertyAssignment = false, }, "class A { public string? Value { get; set; } }", "class B { public string? Value { get; set; } }" @@ -226,7 +226,7 @@ public void NullableStringToNullableStringPropertyWithNoNullAssignmentAndThrow() TestSourceBuilderOptions.Default with { AllowNullPropertyAssignment = false, - ThrowOnPropertyMappingNullMismatch = true + ThrowOnPropertyMappingNullMismatch = true, }, "class A { public string? Value { get; set; } }", "class B { public string? Value { get; set; } }" @@ -337,7 +337,7 @@ public void NullableClassToNullableClassPropertyWithNoNullAssignment() "B", TestSourceBuilderOptions.Default with { - AllowNullPropertyAssignment = false + AllowNullPropertyAssignment = false, }, "class A { public C? Value { get; set; } }", "class B { public D? Value { get; set; } }", @@ -369,7 +369,7 @@ public void NullableClassToNullableClassPropertyWithNoNullAssignmentThrow() TestSourceBuilderOptions.Default with { AllowNullPropertyAssignment = false, - ThrowOnPropertyMappingNullMismatch = true + ThrowOnPropertyMappingNullMismatch = true, }, "class A { public C? Value { get; set; } }", "class B { public D? Value { get; set; } }", @@ -491,7 +491,7 @@ public void NullableClassToNonNullableClassPropertyThrow() "B", TestSourceBuilderOptions.Default with { - ThrowOnPropertyMappingNullMismatch = true + ThrowOnPropertyMappingNullMismatch = true, }, "class A { public C? Value { get; set; } }", "class B { public D Value { get; set; } }", @@ -561,7 +561,7 @@ public void NullableClassToNullableClassPropertyThrowShouldSetNull() "B", TestSourceBuilderOptions.Default with { - ThrowOnPropertyMappingNullMismatch = true + ThrowOnPropertyMappingNullMismatch = true, }, "class A { public C? Value { get; set; } }", "class B { public D? Value { get; set; } }", @@ -603,7 +603,7 @@ public void NullableClassToNullableClassFlattenedPropertyThrow() """, TestSourceBuilderOptions.Default with { - ThrowOnPropertyMappingNullMismatch = true + ThrowOnPropertyMappingNullMismatch = true, }, "class A { public C? Value { get; set; } }", "class B { public D? Value { get; set; } public string ValueFlattened { get; set; } }", diff --git a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyValueTest.cs b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyValueTest.cs index a5781d9eff..f8d94cc84f 100644 --- a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyValueTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyValueTest.cs @@ -155,7 +155,7 @@ public void StringToPrivateField() """[MapValue("_stringValue", "fooBar")] partial B Map(A source);""", TestSourceBuilderOptions.Default with { - IncludedMembers = MemberVisibility.Private + IncludedMembers = MemberVisibility.Private, }, "class A;", "class B { private string _stringValue; }" diff --git a/test/Riok.Mapperly.Tests/Mapping/ObjectVisibilityTest.cs b/test/Riok.Mapperly.Tests/Mapping/ObjectVisibilityTest.cs index 735070bc6e..97ebe36c3f 100644 --- a/test/Riok.Mapperly.Tests/Mapping/ObjectVisibilityTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/ObjectVisibilityTest.cs @@ -81,7 +81,7 @@ public void InternalOtherAssemblyToInternalShouldIgnore() var source = TestSourceBuilder.Mapping("A.A", "B", "class B { internal string Value { get; set; } }"); TestHelper - .GenerateMapper(source, TestHelperOptions.AllowDiagnostics, new[] { aAssembly }) + .GenerateMapper(source, TestHelperOptions.AllowDiagnostics, [aAssembly]) .Should() .HaveDiagnostic(DiagnosticDescriptors.SourceMemberNotFound) .HaveAssertedAllDiagnostics() @@ -112,7 +112,7 @@ public class A { public string PublicValue { get; set; } internal string Interna ); TestHelper - .GenerateMapper(source, TestHelperOptions.AllowDiagnostics, new[] { aAssembly }) + .GenerateMapper(source, TestHelperOptions.AllowDiagnostics, [aAssembly]) .Should() .HaveDiagnostic(DiagnosticDescriptors.SourceMemberNotFound) .HaveAssertedAllDiagnostics() @@ -146,7 +146,7 @@ public class A { public string PublicValue { get; set; } internal string Interna ); TestHelper - .GenerateMapper(source, TestHelperOptions.Default, new[] { aAssembly }) + .GenerateMapper(source, TestHelperOptions.Default, [aAssembly]) .Should() .HaveSingleMethodBody( """ @@ -179,7 +179,7 @@ internal class A { public string PublicValue { get; set; } internal string Inter ); TestHelper - .GenerateMapper(source, TestHelperOptions.Default, new[] { aAssembly }) + .GenerateMapper(source, TestHelperOptions.Default, [aAssembly]) .Should() .HaveSingleMethodBody( """ diff --git a/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionEnumTest.cs b/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionEnumTest.cs index c3226495ca..d0ad6e6688 100644 --- a/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionEnumTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionEnumTest.cs @@ -28,7 +28,7 @@ public void EnumToAnotherEnumByNameShouldDiagnostic() "System.Linq.IQueryable", TestSourceBuilderOptions.Default with { - EnumMappingStrategy = EnumMappingStrategy.ByName + EnumMappingStrategy = EnumMappingStrategy.ByName, }, "class A { public C Value { get; set; } }", "class B { public D Value { get; set; } }", @@ -58,7 +58,7 @@ public void EnumToAnotherEnumByValueWithExplicitMappingShouldDiagnostic() """, TestSourceBuilderOptions.Default with { - EnumMappingStrategy = EnumMappingStrategy.ByValue + EnumMappingStrategy = EnumMappingStrategy.ByValue, }, "class A { public C Value { get; set; } }", "class B { public D Value { get; set; } }", diff --git a/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionNullableTest.cs b/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionNullableTest.cs index ec9490ac44..805ea2fa81 100644 --- a/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionNullableTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/QueryableProjectionNullableTest.cs @@ -76,7 +76,7 @@ public Task ClassToClassNullableSourceAndTargetPropertyWithNoNullAssignmentAndTh TestSourceBuilderOptions.Default with { AllowNullPropertyAssignment = false, - ThrowOnPropertyMappingNullMismatch = true + ThrowOnPropertyMappingNullMismatch = true, }, "class A { public string? StringValue { get; set; } }", "class B { public string? StringValue { get; set; } }" diff --git a/test/Riok.Mapperly.Tests/Mapping/UnsafeAccessorTest.cs b/test/Riok.Mapperly.Tests/Mapping/UnsafeAccessorTest.cs index 4c79b3f7e0..01aedd0071 100644 --- a/test/Riok.Mapperly.Tests/Mapping/UnsafeAccessorTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/UnsafeAccessorTest.cs @@ -190,7 +190,7 @@ public Task ManualUnflattenedPropertyNullablePathWithPrivateConstructor() TestSourceBuilderOptions.Default with { IncludedMembers = MemberVisibility.All, - IncludedConstructors = MemberVisibility.All + IncludedConstructors = MemberVisibility.All, }, "class A { public string MyValueId { get; set; } public string MyValueId2 { get; set; } }", "class B { private C? Value { get; set; } }", diff --git a/test/Riok.Mapperly.Tests/Mapping/UserMethodTest.cs b/test/Riok.Mapperly.Tests/Mapping/UserMethodTest.cs index e32261c298..1865fdee5d 100644 --- a/test/Riok.Mapperly.Tests/Mapping/UserMethodTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/UserMethodTest.cs @@ -718,7 +718,7 @@ public Task ShouldDiscoverBaseClassPartialMappingMethodsWithDisabledAutoUserMapp "B", TestSourceBuilderOptions.WithBaseClass("BaseMapper") with { - AutoUserMappings = false + AutoUserMappings = false, }, """ [Mapper] @@ -743,7 +743,7 @@ public Task ShouldNotDiscoverInterfaceMappingMethodsWithDisabledAutoUserMappings "B", TestSourceBuilderOptions.WithBaseClass("IBaseMapper") with { - AutoUserMappings = false + AutoUserMappings = false, }, """ public interface IBaseMapper diff --git a/test/Riok.Mapperly.Tests/TestHelper.cs b/test/Riok.Mapperly.Tests/TestHelper.cs index c3291e8b21..bdbd6b18bd 100644 --- a/test/Riok.Mapperly.Tests/TestHelper.cs +++ b/test/Riok.Mapperly.Tests/TestHelper.cs @@ -39,7 +39,7 @@ public static MapperGenerationResult GenerateMapper( ?.GetRoot(); var methods = ExtractAllMethods(syntaxRoot).Select(x => new GeneratedMethod(x)).ToDictionary(x => x.Name); - var ignoredDiagnosticDescriptorIds = options.IgnoredDiagnostics?.Select(x => x.Id).ToHashSet() ?? new HashSet(); + var ignoredDiagnosticDescriptorIds = options.IgnoredDiagnostics?.Select(x => x.Id).ToHashSet() ?? []; var filteredDiagnostics = result.Diagnostics.Where(x => !ignoredDiagnosticDescriptorIds.Contains(x.Descriptor.Id)).ToList(); var groupedDiagnostics = filteredDiagnostics .GroupBy(x => x.Descriptor.Id) @@ -73,10 +73,7 @@ public static GeneratorDriver GenerateTracked(Compilation compilation) { var generator = new MapperGenerator(); - var driver = CSharpGeneratorDriver.Create( - new[] { generator.AsSourceGenerator() }, - driverOptions: _enableIncrementalTrackingDriverOptions - ); + var driver = CSharpGeneratorDriver.Create([generator.AsSourceGenerator()], driverOptions: _enableIncrementalTrackingDriverOptions); return driver.RunGenerators(compilation); } diff --git a/test/Riok.Mapperly.Tests/TestHelperOptions.cs b/test/Riok.Mapperly.Tests/TestHelperOptions.cs index 1294856fed..9ae6025bfb 100644 --- a/test/Riok.Mapperly.Tests/TestHelperOptions.cs +++ b/test/Riok.Mapperly.Tests/TestHelperOptions.cs @@ -30,15 +30,15 @@ public record TestHelperOptions( public static readonly TestHelperOptions DisabledNullable = Default with { NullableOption = NullableContextOptions.Disable }; - public static readonly TestHelperOptions AllowDiagnostics = Default with { AllowedDiagnosticSeverities = null, }; + public static readonly TestHelperOptions AllowDiagnostics = Default with { AllowedDiagnosticSeverities = null }; /// /// Includes all ignored diagnostics. /// - public static readonly TestHelperOptions AllowAndIncludeAllDiagnostics = AllowDiagnostics with { IgnoredDiagnostics = null, }; + public static readonly TestHelperOptions AllowAndIncludeAllDiagnostics = AllowDiagnostics with { IgnoredDiagnostics = null }; public static readonly TestHelperOptions AllowInfoDiagnostics = Default with { - AllowedDiagnosticSeverities = new HashSet { DiagnosticSeverity.Hidden, DiagnosticSeverity.Info } + AllowedDiagnosticSeverities = new HashSet { DiagnosticSeverity.Hidden, DiagnosticSeverity.Info }, }; }