pre-refacotring

This commit is contained in:
CodeLiturgy 2022-09-05 02:16:08 +01:00
parent 1de6350c7d
commit 8a664db1f7
2 changed files with 23 additions and 35 deletions

View File

@ -78,7 +78,8 @@ namespace MapTo
private static string GetCsxMethodTemplate(GeneratorExecutionContext context, string templateName)
{
return context.AdditionalFiles
return context
.AdditionalFiles
.FirstOrDefault(x => x.Path.Contains(templateName))?
.GetText()?
.ToString() ?? string.Empty;

View File

@ -35,41 +35,24 @@ namespace MapTo.Sources
.WriteOpeningBracket()
.WriteLine();
var entityTypeName = "";
foreach (var methodModel in model.MethodsModels)
{
if (methodModel is EfAddMethodsModel m)
{
entityTypeName = m.Entity.EntityTypeIdentifierName;
var entityTypeFullName = m.Entity.EntityTypeFullName;
var propertyName = m.Entity.PropertyName;
builder
.EfAddAddEntityMethod(m, addSourceTemplate,
entityTypeName,
contextFullName,
entityTypeFullName,
propertyName);
.EfAddAddEntityMethod(model,m, addSourceTemplate)
.WriteLine();
continue;
}
if (methodModel is EfUpdateMethodsModel updateModel)
{
entityTypeName = updateModel.Entity.EntityTypeIdentifierName;
var entityTypeFullName = updateModel.Entity.EntityTypeFullName;
var propertyName = updateModel.Entity.PropertyName;
builder
.WriteLine()
.EfAddUpdateEntityMethod(updateModel, updateSourceTemplate,
entityTypeName,
contextFullName,
entityTypeFullName,
propertyName);
.EfAddUpdateEntityMethod(model, updateModel, updateSourceTemplate)
.WriteLine();
continue;
}
builder.WriteLine();
}
builder
@ -87,36 +70,38 @@ namespace MapTo.Sources
private static SourceBuilder ParseTemplate(this SourceBuilder builder, string finalTemplate)
{
string[] array = finalTemplate.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (var line in array)
{
for (var i = 0; i < array.Length; i++)
{
var line = array[i];
builder.WriteLine(line);
}
return builder;
}
private static SourceBuilder EfAddAddEntityMethod(this SourceBuilder builder, EfAddMethodsModel model, string addSourceTemplate, string entityTypeName,
string contextFullName, string entityTypeFullName, string propertyName)
private static SourceBuilder EfAddAddEntityMethod(this SourceBuilder builder, EfMethodsModel methodsModel, EfAddMethodsModel model, string addSourceTemplate)
{
var returnTypeFullName = model.ReturnTypeFullName;
var createTypeFullName = model.CreateTypeFullName;
var newEntityVarName = $"new{model.Entity.EntityTypeIdentifierName}";
var toCreateVarName = $"{model.Entity.EntityTypeIdentifierName.ToCamelCase()}ToCreate";
var entityTypeName = model.Entity.EntityTypeIdentifierName;
var contextFullName = methodsModel.ContextFullType;
var propertyName = model.Entity.PropertyName;
if (!addSourceTemplate.IsEmpty())
{
var templateToSourceBuilder = new StringBuilder(addSourceTemplate);
templateToSourceBuilder
.Replace("{entityTypeName}", entityTypeName)
.Replace("{entityTypeName}", model.Entity.EntityTypeIdentifierName)
.Replace("{returnTypeFullName}", returnTypeFullName)
.Replace("{createTypeFullName}", createTypeFullName)
.Replace("{contextFullName}", contextFullName)
.Replace("{toCreateVarName}", toCreateVarName)
.Replace("{newEntityVarName}", newEntityVarName)
.Replace("{entityTypeFullName}", entityTypeFullName)
.Replace("{entityTypeFullName}", model.Entity.EntityTypeFullName)
.Replace("{propertyName}", propertyName);
builder
@ -145,12 +130,14 @@ namespace MapTo.Sources
return builder;
}
private static SourceBuilder EfAddUpdateEntityMethod(this SourceBuilder builder, EfUpdateMethodsModel model, string updateSourceTemplate, string entityTypeName,
string contextFullName, string entityTypeFullName, string propertyName)
private static SourceBuilder EfAddUpdateEntityMethod(this SourceBuilder builder, EfMethodsModel methodsModel, EfUpdateMethodsModel model, string updateSourceTemplate)
{
var entityTypeName = model.Entity.EntityTypeIdentifierName;
var contextFullName = methodsModel.ContextFullType;
var propertyName = model.Entity.PropertyName;
var returnTypeFullName = model.ReturnTypeFullName;
var updateTypeFullName = model.UpdateTypeFullName;
var updateVarName = $"{model.Entity.EntityTypeIdentifierName.ToCamelCase()}ToUpdate";
var updateVarName = $"{entityTypeName.ToCamelCase()}ToUpdate";
var keyPropertyName = model.keyPropertyName;
var keyTypeFullName = model.keyFullTypeName;
var existingVarName = entityTypeName.ToCamelCase();