RoyalCode.SmartSelector.Generators
0.2.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package RoyalCode.SmartSelector.Generators --version 0.2.0
NuGet\Install-Package RoyalCode.SmartSelector.Generators -Version 0.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RoyalCode.SmartSelector.Generators" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RoyalCode.SmartSelector.Generators" Version="0.2.0" />
<PackageReference Include="RoyalCode.SmartSelector.Generators" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RoyalCode.SmartSelector.Generators --version 0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RoyalCode.SmartSelector.Generators, 0.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RoyalCode.SmartSelector.Generators@0.2.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RoyalCode.SmartSelector.Generators&version=0.2.0
#tool nuget:?package=RoyalCode.SmartSelector.Generators&version=0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SmartSelector
Gerador/Source Generator para criar automaticamente proje��es (Expression<Func<TFrom, TDto>>), m�todos auxiliares e propriedades em DTOs, reduzindo drasticamente boilerplate em consultas LINQ / EF Core.
Principais Recursos
[AutoSelect<TFrom>]: gera express�o de sele��o, m�todoFrom, extens�esSelect{Dto}/To{Dto}.[AutoProperties]ou[AutoProperties<TFrom>]: gera propriedades simples automaticamente (primitivos, string, bool, DateTime, enum, struct, cole��es simplesIEnumerable<T>desses tipos).- Flattening por conven��o: nomes concatenados em PascalCase resolvem cadeias aninhadas (ex.:
CustomerAddressCountryRegionName?a.Customer.Address.Country.Region.Name). - Exclus�o de propriedades:
Exclude = [ nameof(Entity.Prop) ]. - Diagn�sticos de compila��o para uso incorreto, tipos incompat�veis e conflitos.
Instala��o
<ItemGroup>
<PackageReference Include="RoyalCode.SmartSelector" Version="x.y.z" />
<PackageReference Include="RoyalCode.SmartSelector.Generators" Version="x.y.z" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
Exemplo 1 � Proje��o Simples
[AutoSelect<User>, AutoProperties]
public partial class UserDetails { }
// Uso
var list = db.Users.SelectUserDetails().ToList();
var dto = UserDetails.From(user);
var expr = UserDetails.SelectUserExpression; // reutiliz�vel / compon�vel
C�digo gerado (essencial):
public static Expression<Func<User, UserDetails>> SelectUserExpression => u => new UserDetails { Id = u.Id, Name = u.Name };
public static UserDetails From(User u) => (selectUserFunc ??= SelectUserExpression.Compile())(u);
Exemplo 2 � Objeto Aninhado + Exclus�o
[AutoSelect<Book>, AutoProperties(Exclude = [ nameof(Book.Sku) ])]
public partial class BookDetails
{
public ShelfDetails Shelf { get; set; }
}
[AutoProperties<Shelf>]
public partial class ShelfDetails { }
Trecho gerado:
Shelf = new ShelfDetails { Id = a.Shelf.Id, Location = a.Shelf.Location },
Price = a.Price,
// Sku exclu�do
Exemplo 3 � Flattening Profundo
public class Order { public Customer Customer { get; set; } }
// Customer -> Address -> Country -> Region
[AutoSelect<Order>]
public partial class OrderDetails
{
public string CustomerAddressCountryRegionName { get; set; }
}
Trecho da express�o:
CustomerAddressCountryRegionName = a.Customer.Address.Country.Region.Name
Regras de Flattening
- Nome da propriedade = concatena��o PascalCase dos segmentos do caminho.
- Sem necessidade de atributos extras.
Tipos Suportados em AutoProperties
- Primitivos num�ricos,
bool,string,char,DateTime/ nullable simples enum,structIEnumerable<T>ondeT� suportado acima / enum / struct
Exclus�es
[AutoProperties<Product>(Exclude = [ nameof(Product.InternalCode), nameof(Product.Secret) ])]
Diagn�sticos Principais
- Tipos inv�lidos ou classe n�o
partial(RCSS000). - Propriedade n�o encontrada (
RCSS001). - Tipos incompat�veis (
RCSS002). - Uso incorreto de atributos (
RCSS003�RCSS005).
Limita��es Resumidas
- Sem renome/alias expl�cito ainda (
MapFrom). - Sem transforma��es de tipo (formatters / custom converters).
- Desambigua��o de flattening limitada em colis�es de prefixo.
Boas Pr�ticas
- Use
nameofemExclude. - Prefira consumir a express�o gerada para reutiliza��o e composi��o LINQ.
- Para caminhos muito longos, avalie DTOs aninhados por clareza.
FAQ R�pido
| Pergunta | Resposta |
|---|---|
| Preciso configurar algo no runtime? | N�o, pura gera��o de c�digo. |
| Funciona com EF Core? | Sim, a express�o � traduz�vel. |
| Posso s� gerar propriedades? | Sim: [AutoProperties<TFrom>]. |
| Flattening precisa de atributo? | N�o, � por nome. |
Mais Informa��es
Documenta��o detalhada: ver docs.md no reposit�rio.
Happy coding!
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- RoyalCode.Extensions.SourceGenerator (>= 0.1.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.