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..debf2eb9bc 100644 --- a/src/Riok.Mapperly/Descriptors/Enumerables/CollectionInfoBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/Enumerables/CollectionInfoBuilder.cs @@ -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/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/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/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..7d3622ff4a 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBuilders/MappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBuilders/MappingBuilder.cs @@ -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..849f256a83 100644 --- a/src/Riok.Mapperly/Descriptors/MappingCollection.cs +++ b/src/Riok.Mapperly/Descriptors/MappingCollection.cs @@ -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"), }; } @@ -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/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/UserImplementedInlinedExpressionMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedInlinedExpressionMapping.cs index 6e54214687..e971f81c0d 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedInlinedExpressionMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/UserMappings/UserImplementedInlinedExpressionMapping.cs @@ -62,7 +62,7 @@ private IEnumerable ExtractOverwrittenIdentifiers(SyntaxNode node) { SimpleLambdaExpressionSyntax simpleLambda => new[] { simpleLambda.Parameter.Identifier }, ParenthesizedLambdaExpressionSyntax lambda => lambda.ParameterList.Parameters.Select(p => p.Identifier), - _ => Enumerable.Empty() + _ => 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..e75b25f3ac 100644 --- a/src/Riok.Mapperly/Descriptors/UnsafeAccess/UnsafeAccessorContext.cs +++ b/src/Riok.Mapperly/Descriptors/UnsafeAccess/UnsafeAccessorContext.cs @@ -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/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/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.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..edf573cd84 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,7 +29,7 @@ public void RemoveRangeShouldRemoveEntries() { ["a"] = 10, ["b"] = 20, - ["c"] = 30 + ["c"] = 30, }; d.RemoveRange(new[] { "a", "c" }); d.Keys.Should().BeEquivalentTo("b"); @@ -38,7 +38,7 @@ public void RemoveRangeShouldRemoveEntries() [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/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/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/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/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 }, }; }