pre-refacotring
This commit is contained in:
parent
1de6350c7d
commit
8a664db1f7
|
@ -78,7 +78,8 @@ namespace MapTo
|
||||||
|
|
||||||
private static string GetCsxMethodTemplate(GeneratorExecutionContext context, string templateName)
|
private static string GetCsxMethodTemplate(GeneratorExecutionContext context, string templateName)
|
||||||
{
|
{
|
||||||
return context.AdditionalFiles
|
return context
|
||||||
|
.AdditionalFiles
|
||||||
.FirstOrDefault(x => x.Path.Contains(templateName))?
|
.FirstOrDefault(x => x.Path.Contains(templateName))?
|
||||||
.GetText()?
|
.GetText()?
|
||||||
.ToString() ?? string.Empty;
|
.ToString() ?? string.Empty;
|
||||||
|
|
|
@ -35,41 +35,24 @@ namespace MapTo.Sources
|
||||||
.WriteOpeningBracket()
|
.WriteOpeningBracket()
|
||||||
.WriteLine();
|
.WriteLine();
|
||||||
|
|
||||||
var entityTypeName = "";
|
|
||||||
foreach (var methodModel in model.MethodsModels)
|
foreach (var methodModel in model.MethodsModels)
|
||||||
{
|
{
|
||||||
if (methodModel is EfAddMethodsModel m)
|
if (methodModel is EfAddMethodsModel m)
|
||||||
{
|
{
|
||||||
entityTypeName = m.Entity.EntityTypeIdentifierName;
|
|
||||||
var entityTypeFullName = m.Entity.EntityTypeFullName;
|
|
||||||
var propertyName = m.Entity.PropertyName;
|
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.EfAddAddEntityMethod(m, addSourceTemplate,
|
.EfAddAddEntityMethod(model,m, addSourceTemplate)
|
||||||
entityTypeName,
|
.WriteLine();
|
||||||
contextFullName,
|
continue;
|
||||||
entityTypeFullName,
|
|
||||||
propertyName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (methodModel is EfUpdateMethodsModel updateModel)
|
if (methodModel is EfUpdateMethodsModel updateModel)
|
||||||
{
|
{
|
||||||
entityTypeName = updateModel.Entity.EntityTypeIdentifierName;
|
|
||||||
var entityTypeFullName = updateModel.Entity.EntityTypeFullName;
|
|
||||||
var propertyName = updateModel.Entity.PropertyName;
|
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.WriteLine()
|
.EfAddUpdateEntityMethod(model, updateModel, updateSourceTemplate)
|
||||||
.EfAddUpdateEntityMethod(updateModel, updateSourceTemplate,
|
.WriteLine();
|
||||||
entityTypeName,
|
continue;
|
||||||
contextFullName,
|
|
||||||
entityTypeFullName,
|
|
||||||
propertyName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.WriteLine();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder
|
builder
|
||||||
|
@ -88,35 +71,37 @@ namespace MapTo.Sources
|
||||||
{
|
{
|
||||||
string[] array = finalTemplate.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
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);
|
builder.WriteLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SourceBuilder EfAddAddEntityMethod(this SourceBuilder builder, EfAddMethodsModel model, string addSourceTemplate, string entityTypeName,
|
private static SourceBuilder EfAddAddEntityMethod(this SourceBuilder builder, EfMethodsModel methodsModel, EfAddMethodsModel model, string addSourceTemplate)
|
||||||
string contextFullName, string entityTypeFullName, string propertyName)
|
|
||||||
{
|
{
|
||||||
var returnTypeFullName = model.ReturnTypeFullName;
|
var returnTypeFullName = model.ReturnTypeFullName;
|
||||||
var createTypeFullName = model.CreateTypeFullName;
|
var createTypeFullName = model.CreateTypeFullName;
|
||||||
var newEntityVarName = $"new{model.Entity.EntityTypeIdentifierName}";
|
var newEntityVarName = $"new{model.Entity.EntityTypeIdentifierName}";
|
||||||
var toCreateVarName = $"{model.Entity.EntityTypeIdentifierName.ToCamelCase()}ToCreate";
|
var toCreateVarName = $"{model.Entity.EntityTypeIdentifierName.ToCamelCase()}ToCreate";
|
||||||
|
|
||||||
|
var entityTypeName = model.Entity.EntityTypeIdentifierName;
|
||||||
|
var contextFullName = methodsModel.ContextFullType;
|
||||||
|
var propertyName = model.Entity.PropertyName;
|
||||||
|
|
||||||
if (!addSourceTemplate.IsEmpty())
|
if (!addSourceTemplate.IsEmpty())
|
||||||
{
|
{
|
||||||
var templateToSourceBuilder = new StringBuilder(addSourceTemplate);
|
var templateToSourceBuilder = new StringBuilder(addSourceTemplate);
|
||||||
templateToSourceBuilder
|
templateToSourceBuilder
|
||||||
.Replace("{entityTypeName}", entityTypeName)
|
.Replace("{entityTypeName}", model.Entity.EntityTypeIdentifierName)
|
||||||
.Replace("{returnTypeFullName}", returnTypeFullName)
|
.Replace("{returnTypeFullName}", returnTypeFullName)
|
||||||
.Replace("{createTypeFullName}", createTypeFullName)
|
.Replace("{createTypeFullName}", createTypeFullName)
|
||||||
.Replace("{contextFullName}", contextFullName)
|
.Replace("{contextFullName}", contextFullName)
|
||||||
.Replace("{toCreateVarName}", toCreateVarName)
|
.Replace("{toCreateVarName}", toCreateVarName)
|
||||||
.Replace("{newEntityVarName}", newEntityVarName)
|
.Replace("{newEntityVarName}", newEntityVarName)
|
||||||
.Replace("{entityTypeFullName}", entityTypeFullName)
|
.Replace("{entityTypeFullName}", model.Entity.EntityTypeFullName)
|
||||||
.Replace("{propertyName}", propertyName);
|
.Replace("{propertyName}", propertyName);
|
||||||
|
|
||||||
builder
|
builder
|
||||||
|
@ -145,12 +130,14 @@ namespace MapTo.Sources
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SourceBuilder EfAddUpdateEntityMethod(this SourceBuilder builder, EfUpdateMethodsModel model, string updateSourceTemplate, string entityTypeName,
|
private static SourceBuilder EfAddUpdateEntityMethod(this SourceBuilder builder, EfMethodsModel methodsModel, EfUpdateMethodsModel model, string updateSourceTemplate)
|
||||||
string contextFullName, string entityTypeFullName, string propertyName)
|
|
||||||
{
|
{
|
||||||
|
var entityTypeName = model.Entity.EntityTypeIdentifierName;
|
||||||
|
var contextFullName = methodsModel.ContextFullType;
|
||||||
|
var propertyName = model.Entity.PropertyName;
|
||||||
var returnTypeFullName = model.ReturnTypeFullName;
|
var returnTypeFullName = model.ReturnTypeFullName;
|
||||||
var updateTypeFullName = model.UpdateTypeFullName;
|
var updateTypeFullName = model.UpdateTypeFullName;
|
||||||
var updateVarName = $"{model.Entity.EntityTypeIdentifierName.ToCamelCase()}ToUpdate";
|
var updateVarName = $"{entityTypeName.ToCamelCase()}ToUpdate";
|
||||||
var keyPropertyName = model.keyPropertyName;
|
var keyPropertyName = model.keyPropertyName;
|
||||||
var keyTypeFullName = model.keyFullTypeName;
|
var keyTypeFullName = model.keyFullTypeName;
|
||||||
var existingVarName = entityTypeName.ToCamelCase();
|
var existingVarName = entityTypeName.ToCamelCase();
|
||||||
|
|
Loading…
Reference in New Issue