Maestria.TypeProviders
1.1.2
dotnet add package Maestria.TypeProviders --version 1.1.2
NuGet\Install-Package Maestria.TypeProviders -Version 1.1.2
<PackageReference Include="Maestria.TypeProviders" Version="1.1.2"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Maestria.TypeProviders --version 1.1.2
#r "nuget: Maestria.TypeProviders, 1.1.2"
// Install Maestria.TypeProviders as a Cake Addin #addin nuget:?package=Maestria.TypeProviders&version=1.1.2 // Install Maestria.TypeProviders as a Cake Tool #tool nuget:?package=Maestria.TypeProviders&version=1.1.2
Maestria.Type.Providers
What is Maestria.Type.Providers?
Source Generator pack to increase productivity and improve source code writing.
How install and configure package?
First, install Maestria.Type.Providers from the dotnet cli command line:
dotnet add package Maestria.TypeProviders
Providers x Dependencies
This package does not include dependencies references when installed on your project, its only generate source code files.
You need install thirds dependencies to compile your project according to the features used, bellow instructions of source generator providers:
- ExcelProvider: Generated strong data sctruct and factory class to load xls/xlsx data.
- OpenApiProvider: Generate HTTP client from OpenApi / Swagger specification.
ExcelProvider
Generate strong data struct and class factory to load excel data from xls/xlsx template.
Attribute: ExcelProvider
Dependencies
Dependencies install
dotnet add package Maestria.Extensions.FluentCast
dotnet add package ClosedXML
Use case sample
// The relative path is based at the source code file location.
// In this example the first page was used as none were explicitly entered.
[ExcelProvider(TemplatePath = @"../../resources/Excel.xlsx")]
public partial class MyExcelData
{
}
var data = MyExcelDataFactory.Load(filePath);
foreach (var item in data)
// Access strong typing by "item.<field-name>"
Use case sample two
// The relative path is based at the source code file location.
// Loadind data struct from second page
[ExcelProvider(TemplatePath = @"../../resources/Excel.xlsx", SheetName = "Plan2")]
public partial class MyExcelData
{
}
var data = MyExcelDataFactory.Load(filePath, "Plan2");
foreach (var item in data)
// Access strong typing by "item.<field-name>"
Generator engine:
Nullable types
: To create a nullable property, seed excel template file with one row cell empty, and another not empty.Decimal types
: To create decimal property, seed one row of cell with floating point value.
Good practices: Don't use big file by template, this file is used always you need recreated source code. Big file impact is slow build time.
OpenApiProvider
Provider to generate source code HTTP client from OpenApi / Swagger specification.
It's planned used NSwagStudio engine with .NET 5 source generator.
This package allows automatized generation code.
...As soon as possible
Troubleshooting
Optional configuration in VS Code: To view the automatically generated codes it is necessary to indicate to write it to disk with the configuration in the .csproj
file.
On CompilerGeneratedFilesOutputPath
property its configured with /../generated/$(MSBuildProjectName)
. This folder is one level above of file project on this sample.
This mode allow see generated files, but not works go to navigation
feature of VS Code.
<PropertyGroup>
<CompilerGeneratedFilesOutputPath>$(MSBuildProjectDirectory)/../generated/$(MSBuildProjectName)</CompilerGeneratedFilesOutputPath>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>
Optional configuration in VS Code: To allow go to navigation
feature you need write files at solution level.
Problem's: The source code generated will be used on next build, to solve problems of duplicated classes, it's need removed generated files before build.
On next build, if there was no change on yout source code used by generators, the files has no generated. You need force a rebuild withdotnet build --no-incremental <args>
to regenerate files.
<PropertyGroup>
<CompilerGeneratedFilesOutputPath>$(MSBuildProjectDirectory)/generated/$(MSBuildProjectName)</CompilerGeneratedFilesOutputPath>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>
<Target Name="ExcludeGenerated" BeforeTargets="AssignTargetPaths">
<ItemGroup>
<Generated Include="/generated/**/*.cs" />
<Compile Remove="@(Generated)" />
</ItemGroup>
<Delete Files="@(Generated)" />
</Target>
If my contributions helped you, please help me buy a coffee 😄
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.