Add code generation.
Replaces the client and server controller implementations with generated code from the shared project.
This commit is contained in:
91
EstusShots.Client/Routes.tt
Normal file
91
EstusShots.Client/Routes.tt
Normal file
@@ -0,0 +1,91 @@
|
||||
<#@ template language="C#" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ assembly name="$(SolutionDir)EstusShots.Shared/bin/Debug/netcoreapp3.1/EstusShots.Shared.dll" #>
|
||||
<#@ import namespace="Shared.Interfaces" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#
|
||||
var assembly = typeof(IApiParameter).Assembly;
|
||||
var types = assembly.GetTypes()
|
||||
.Where(t => t.Namespace?.StartsWith("EstusShots.Shared") == true)
|
||||
.ToArray();
|
||||
var controllers = types
|
||||
.Where(t => t.Namespace == "EstusShots.Shared.Interfaces.Controllers")
|
||||
.ToArray();
|
||||
#>
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Threading.Tasks;
|
||||
using EstusShots.Shared.Models;
|
||||
using EstusShots.Shared.Models.Parameters;
|
||||
using EstusShots.Shared.Interfaces.Controllers;
|
||||
|
||||
namespace EstusShots.Client
|
||||
{
|
||||
// Generated part of the client class
|
||||
public partial class EstusShotsClient
|
||||
{
|
||||
<#
|
||||
// Create API client route properties
|
||||
foreach (var iFace in controllers)
|
||||
{
|
||||
var className = iFace.Name.Substring(1).Replace("Controller", "");
|
||||
#>
|
||||
public <#=className#> <#=className#> { get; internal set; }
|
||||
<#
|
||||
}
|
||||
#>
|
||||
|
||||
private void CreateApiRoutes()
|
||||
{
|
||||
<#
|
||||
// Instantiate API client routes
|
||||
foreach (var iFace in controllers)
|
||||
{
|
||||
var className = iFace.Name.Substring(1).Replace("Controller", "");
|
||||
#>
|
||||
<#=className#> = new <#=className#>(this);
|
||||
<#
|
||||
}
|
||||
#>
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
foreach (var iFace in controllers)
|
||||
{
|
||||
var className = iFace.Name.Substring(1).Replace("Controller", "");
|
||||
#>
|
||||
public class <#=className#> : <#=iFace.Name #>
|
||||
{
|
||||
private readonly EstusShotsClient _client;
|
||||
|
||||
public <#=className#>(EstusShotsClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
<#
|
||||
foreach (var member in iFace.GetMembers())
|
||||
{
|
||||
var responseName = $"{member.Name}Response";
|
||||
var parameterName = $"{member.Name}Parameter";
|
||||
#>
|
||||
public async Task<ApiResponse<<#=responseName#>>> <#=member.Name#>(<#=parameterName#> parameter)
|
||||
=> await _client.PostToApi<<#=responseName#>, <#=parameterName#>>($"{_client.ApiUrl}<#=className#>/<#=member.Name#>", parameter);
|
||||
|
||||
<#
|
||||
}
|
||||
#>
|
||||
}
|
||||
|
||||
<#
|
||||
}
|
||||
#>
|
||||
}
|
||||
Reference in New Issue
Block a user