Skip to content

Commit e3b1729

Browse files
committed
Introduzindo AutoDetails
1 parent 56265c5 commit e3b1729

7 files changed

Lines changed: 68 additions & 52 deletions

File tree

src/RoyalCode.SmartSelector.Generators/Extensions/LocalExtensions.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace RoyalCode.SmartSelector.Generators.Generators;
6+
7+
internal class AutoDetailsGenerator
8+
{
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.CodeAnalysis;
2+
3+
namespace RoyalCode.SmartSelector.Generators.Generators;
4+
5+
internal class AutoDetailsInformation : IEquatable<AutoDetailsInformation>
6+
{
7+
private readonly Diagnostic[]? diagnostics;
8+
9+
private readonly string? detailsClassName;
10+
private readonly AutoPropertiesInformation? autoPropertiesInformation;
11+
12+
public bool Equals(AutoDetailsInformation other)
13+
{
14+
throw new NotImplementedException();
15+
}
16+
}

src/RoyalCode.SmartSelector.Generators/Generators/AutoPropertiesGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ internal static AutoPropertiesInformation CreateInformation(
151151
flattening.Add(fs);
152152

153153
// gera o TypeDescriptor do fromType
154-
var fromTypeDescriptor = fromType.CreateTypeDescriptor();
154+
var fromTypeDescriptor = TypeDescriptor.Create(fromType);
155155

156156
return CreateInformation(modelType, fromTypeDescriptor, excluded, flattening);
157157
}
@@ -219,7 +219,7 @@ private static IReadOnlyList<PropertyDescriptor> CreateFlattening(
219219
continue;
220220

221221
// obtém as propriedades do tipo
222-
var nestedProps = namedType.CreateTypeDescriptor().CreateProperties(p => p.GetMethod is not null);
222+
var nestedProps = TypeDescriptor.Create(namedType).CreateProperties(p => p.GetMethod is not null);
223223
foreach (var np in nestedProps.Where(IsSupportedType))
224224
{
225225
// cria nova propriedade com o nome composto
@@ -276,7 +276,7 @@ private static bool IsSupportedType(PropertyDescriptor descriptor)
276276
var arg = namedType.TypeArguments.FirstOrDefault();
277277
if (arg != null)
278278
{
279-
var argType = arg.CreateTypeDescriptor();
279+
var argType = TypeDescriptor.Create(arg);
280280
return SupportedPrimitiveTypes.Contains(argType.Name)
281281
|| arg.TypeKind == TypeKind.Enum
282282
|| arg.TypeKind == TypeKind.Struct;
@@ -323,7 +323,7 @@ internal static void Generate(AutoPropertiesInformation propertiesInfo, SourcePr
323323
foreach (var p in properties)
324324
{
325325
var propertyType = p.Type.HasNamedTypeSymbol(out var typeSymbol)
326-
? typeSymbol.CreateTypeDescriptor()
326+
? TypeDescriptor.Create(typeSymbol)
327327
: p.Type;
328328

329329
var prop = new PropertyGenerator(propertyType, p.Name);

src/RoyalCode.SmartSelector.Generators/Generators/AutoPropertiesInformation.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ internal class AutoPropertiesInformation : IEquatable<AutoPropertiesInformation>
77
private readonly Diagnostic[]? diagnostics;
88
private readonly PropertyDescriptor[]? properties;
99
private readonly TypeDescriptor originType;
10+
private readonly AutoDetailsInformation[]? autoDetails;
1011

1112
public AutoPropertiesInformation(Diagnostic diagnostic)
1213
{
@@ -18,16 +19,22 @@ public AutoPropertiesInformation(Diagnostic[] diagnostics)
1819
this.diagnostics = diagnostics;
1920
}
2021

21-
public AutoPropertiesInformation(TypeDescriptor originType, PropertyDescriptor[] properties)
22+
public AutoPropertiesInformation(
23+
TypeDescriptor originType,
24+
PropertyDescriptor[] properties,
25+
AutoDetailsInformation[]? autoDetails = null)
2226
{
2327
this.originType = originType;
2428
this.properties = properties;
29+
this.autoDetails = autoDetails;
2530
}
2631

2732
public PropertyDescriptor[] Properties => properties ?? [];
2833

2934
public TypeDescriptor OriginType => originType;
3035

36+
public AutoDetailsInformation[] AutoDetails => autoDetails ?? [];
37+
3138
public bool Equals(AutoPropertiesInformation other)
3239
{
3340
if (other == null)
@@ -39,7 +46,8 @@ public bool Equals(AutoPropertiesInformation other)
3946
return true;
4047
}
4148
return diagnostics?.SequenceEqual(other.diagnostics) == true &&
42-
properties?.SequenceEqual(other.properties) == true;
49+
properties?.SequenceEqual(other.properties) == true &&
50+
autoDetails?.SequenceEqual(other.autoDetails) == true;
4351
}
4452

4553
internal void Generate(SourceProductionContext context)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace RoyalCode.SmartSelector;
2+
3+
/// <summary>
4+
/// <para>
5+
/// This attribute should be used in properties of DTO/Details class types that have
6+
/// the <see cref="AutoPropertiesAttribute{TFrom}"/> or
7+
/// <see cref="AutoSelectAttribute{TFrom}"/> with <see cref="AutoPropertiesAttribute"/>.
8+
/// </para>
9+
/// <para>
10+
/// The class of the property type will be generated.
11+
/// <br />
12+
/// This generation will be similar to AutoProperties, using the property related to TFrom as the source type.
13+
/// </para>
14+
/// </summary>
15+
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
16+
public class AutoDetailsAttribute : Attribute
17+
{
18+
/// <summary>
19+
/// An array of property names to exclude from automatic property handling. Property names are case-sensitive.
20+
/// Can be empty to include all properties.
21+
/// </summary>
22+
public string[]? Exclude { get; set; }
23+
24+
/// <summary>
25+
/// An array of property names to generate flattening for complex/nested properties.
26+
/// Property names are case-sensitive.
27+
/// </summary>
28+
public string[]? Flattening { get; set; }
29+
}

src/RoyalCode.SmartSelector/AutoPropertiesAttribute.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ public class AutoPropertiesAttribute : Attribute
2020
/// Property names are case-sensitive.
2121
/// </summary>
2222
public string[]? Flattening { get; set; }
23-
24-
/// <summary>
25-
/// Initializes a new instance of the AutoPropertiesAttribute class.
26-
/// </summary>
27-
public AutoPropertiesAttribute() { }
2823
}
2924

3025
/// <summary>
@@ -48,9 +43,4 @@ public class AutoPropertiesAttribute<TFrom> : Attribute
4843
/// Property names are case-sensitive.
4944
/// </summary>
5045
public string[]? Flattening { get; set; }
51-
52-
/// <summary>
53-
/// Initializes a new instance of the AutoPropertiesAttribute class.
54-
/// </summary>
55-
public AutoPropertiesAttribute() { }
5646
}

0 commit comments

Comments
 (0)