using System.Collections.Immutable; using System.Linq; using MapTo.Extensions; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace MapTo { internal class StructMappingContext : MappingContext { internal StructMappingContext(Compilation compilation, SourceGenerationOptions sourceGenerationOptions, TypeDeclarationSyntax typeSyntax) : base(compilation, sourceGenerationOptions, typeSyntax) { } protected override ImmutableArray GetSourceMappedFields(ITypeSymbol typeSymbol, ITypeSymbol sourceTypeSymbol, bool isInheritFromMappedBaseClass) { var sourceProperties = sourceTypeSymbol.GetAllMembers().OfType().ToArray(); return typeSymbol .GetAllMembers() .OfType() .Where(p => !p.HasAttribute(IgnoreMemberAttributeTypeSymbol)) .Select(property => MapField(sourceTypeSymbol, sourceProperties, property)) .Where(mappedProperty => mappedProperty is not null) .ToImmutableArray()!; } protected override ImmutableArray GetSourceMappedProperties(ITypeSymbol typeSymbol, ITypeSymbol sourceTypeSymbol, bool hasInheritedClass) { var sourceProperties = sourceTypeSymbol.GetAllMembers().OfType().ToArray(); return typeSymbol .GetAllMembers() .OfType() .Where(p => !p.HasAttribute(IgnoreMemberAttributeTypeSymbol)) .Select(property => MapProperty(sourceTypeSymbol, sourceProperties, property)) .Where(mappedProperty => mappedProperty is not null) .ToImmutableArray()!; } protected override ImmutableArray GetTypeMappedFields(ITypeSymbol typeSymbol, ITypeSymbol sourceTypeSymbol, bool isInheritFromMappedBaseClass) { var sourceProperties = sourceTypeSymbol.GetAllMembers().OfType().ToArray(); return sourceTypeSymbol .GetAllMembers() .OfType() .Where(p => !p.HasAttribute(IgnoreMemberAttributeTypeSymbol)) .Select(property => MapFieldSimple(typeSymbol, property)) .Where(mappedProperty => mappedProperty is not null) .ToImmutableArray()!; } protected override ImmutableArray GetTypeMappedProperties(ITypeSymbol typeSymbol, ITypeSymbol sourceTypeSymbol, bool hasInheritedClass) { var sourceProperties = sourceTypeSymbol.GetAllMembers().OfType().ToArray(); return sourceTypeSymbol .GetAllMembers() .OfType() .Where(p => !p.HasAttribute(IgnoreMemberAttributeTypeSymbol)) .Select(property => MapPropertySimple(typeSymbol, property)) .Where(mappedProperty => mappedProperty is not null) .ToImmutableArray()!; } } }