Better creation in APplyTo
This commit is contained in:
parent
0233a26d54
commit
8a49d88153
|
|
@ -665,7 +665,7 @@ namespace AutoMapProperty
|
|||
return (exprSb.ToString(), projectors);
|
||||
}
|
||||
|
||||
public static string? GeneratePropertyTo(List<ClassToGenerate> otherClasses, string Key, ITypeSymbol FromType, ITypeSymbol ToType, bool nullable = true)
|
||||
public static string? GeneratePropertyTo(ClassToGenerate classToGenerate, List<ClassToGenerate> otherClasses, string Key, ITypeSymbol FromType, ITypeSymbol ToType, bool nullable = true)
|
||||
{
|
||||
|
||||
|
||||
|
|
@ -693,7 +693,7 @@ namespace AutoMapProperty
|
|||
sb.Append(nullable ? "?" : "");
|
||||
if (!SymbolEqualityComparer.Default.Equals(concreteToType, concreteFromType))
|
||||
{
|
||||
sb.Append(@".Select(x => (").Append(GetFullString(concreteFromType)).Append(@")x)");
|
||||
sb.Append(@".Select(x => (").Append(GetFullString(concreteFromType)).Append(@")x.ApplyTo(providers, (").Append(GetFullString(concreteFromType)).Append(@")(AutoMapProperty.AutoMapPropertyUtils.Create<").Append(GetFullString(concreteFromType)).Append(",").Append(classToGenerate.SourceContainer.Identifier).Append(">(providers, source, \"").Append(Key).Append("\"))))");
|
||||
sb.Append(nullable ? "?" : "");
|
||||
}
|
||||
|
||||
|
|
@ -717,14 +717,14 @@ namespace AutoMapProperty
|
|||
}
|
||||
else
|
||||
{
|
||||
// if (otherClasses.Select(x => x.Name).Contains(ToType.Name))
|
||||
// sb.Append("this.").Append(Key).Append(".ApplyTo(providers, source.").Append(Key).Append(")");
|
||||
// else
|
||||
sb.Append("(").Append(GetFullString(FromType)).Append(@")this.").Append(Key);
|
||||
if (otherClasses.Select(x => x.Name).Contains(ToType.Name))
|
||||
sb.Append("this.").Append(Key).Append(".ApplyTo(providers, (").Append(GetFullString(FromType)).Append(@")(source.").Append(Key).Append(" != null ? source.").Append(Key).Append(" : AutoMapProperty.AutoMapPropertyUtils.Create<").Append(GetFullString(FromType)).Append(",").Append(classToGenerate.SourceContainer.Identifier).Append(">(providers, source, \"").Append(Key).Append("\")))");
|
||||
else
|
||||
sb.Append("(").Append(GetFullString(FromType)).Append(@")this.").Append(Key);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
public static string? GenerateCorrectToProperty(List<ClassToGenerate> otherClasses, string Key, ClassToGenerate.MappableTypes Value, bool nullable = true)
|
||||
public static string? GenerateCorrectToProperty(ClassToGenerate classToGenerate, List<ClassToGenerate> otherClasses, string Key, ClassToGenerate.MappableTypes Value, bool nullable = true)
|
||||
{
|
||||
var retSb = new StringBuilder();
|
||||
retSb.Append("source.");
|
||||
|
|
@ -732,7 +732,7 @@ namespace AutoMapProperty
|
|||
{
|
||||
if (Value.FromIsReadOnly)
|
||||
return null;
|
||||
var generated = GeneratePropertyTo(otherClasses, Key, Value.FromType, Value.ToType, nullable);
|
||||
var generated = GeneratePropertyTo(classToGenerate, otherClasses, Key, Value.FromType, Value.ToType, nullable);
|
||||
if (generated == null)
|
||||
return null;
|
||||
retSb.Append(generated);
|
||||
|
|
@ -999,7 +999,7 @@ namespace ").Append(classToGenerate.Namespace).Append(@"
|
|||
{/*
|
||||
if (prop.Value.FromType.IsAbstract)
|
||||
continue;*/
|
||||
var property = GenerateCorrectToProperty(otherClasses, prop.Key, prop.Value);
|
||||
var property = GenerateCorrectToProperty(classToGenerate, otherClasses, prop.Key, prop.Value);
|
||||
if (property == null)
|
||||
continue;
|
||||
sb.Append(@"
|
||||
|
|
@ -1022,13 +1022,12 @@ namespace ").Append(classToGenerate.Namespace).Append(@"
|
|||
sb.Append(@"
|
||||
public ").Append(classToGenerate.SourceContainer.Identifier).Append(@" Create(System.IServiceProvider? providers = null)
|
||||
{
|
||||
var dat = new ").Append(classToGenerate.SourceContainer.Identifier).Append(@"();
|
||||
var dat = AutoMapProperty.AutoMapPropertyUtils.Create<").Append(classToGenerate.SourceContainer.Identifier).Append(@">(providers);
|
||||
return ApplyTo(providers, dat);
|
||||
}
|
||||
public static explicit operator ").Append(classToGenerate.SourceContainer.Identifier).Append(@"(").Append(classToGenerate.Name).Append(@" source)
|
||||
{
|
||||
var dat = new ").Append(classToGenerate.SourceContainer.Identifier).Append(@"();
|
||||
return source.ApplyTo(null, dat);
|
||||
return source.Create(null);
|
||||
}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user