diff --git a/src/MapTo/MappingContext.cs b/src/MapTo/MappingContext.cs index 59160c4..37c3a80 100644 --- a/src/MapTo/MappingContext.cs +++ b/src/MapTo/MappingContext.cs @@ -61,6 +61,7 @@ namespace MapTo MappingContext context = typeSyntax switch { ClassDeclarationSyntax => new ClassMappingContext(compilation, sourceGenerationOptions, typeSyntax), + StructDeclarationSyntax => new StructMappingContext(compilation, sourceGenerationOptions, typeSyntax), RecordDeclarationSyntax => new RecordMappingContext(compilation, sourceGenerationOptions, typeSyntax), _ => throw new ArgumentOutOfRangeException() }; diff --git a/src/MapTo/StructMappingContext.cs b/src/MapTo/StructMappingContext.cs new file mode 100644 index 0000000..25d0173 --- /dev/null +++ b/src/MapTo/StructMappingContext.cs @@ -0,0 +1,27 @@ +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 GetMappedProperties(ITypeSymbol typeSymbol, ITypeSymbol sourceTypeSymbol, bool hasInheritedClass) + { + var sourceProperties = sourceTypeSymbol.GetAllMembers().OfType().ToArray(); + + return typeSymbol + .GetAllMembers() + .OfType() + .Where(p => !p.HasAttribute(IgnorePropertyAttributeTypeSymbol)) + .Select(property => MapProperty(sourceTypeSymbol, sourceProperties, property)) + .Where(mappedProperty => mappedProperty is not null) + .ToImmutableArray()!; + } + } +} \ No newline at end of file