fixup abstract to generation

This commit is contained in:
honzapatCZ 2025-01-11 23:10:22 +01:00
parent ead01089be
commit 90da30344e

View File

@ -213,7 +213,7 @@ namespace AutoMapProperty
try try
{ {
var newList = GetModifiedAttributeList(compilation, propSyntax.AttributeLists); var newList = GetModifiedAttributeList(compilation, propSyntax.AttributeLists);
/* /*
context.ReportDiagnostic(Diagnostic.Create( context.ReportDiagnostic(Diagnostic.Create(
new DiagnosticDescriptor("NEJ23", "Error", "New list on: {1} {0}", "NEJ", DiagnosticSeverity.Warning, true), null, string.Join(", ", newList.Select(x => x.ToString())), propSymbol.Name) new DiagnosticDescriptor("NEJ23", "Error", "New list on: {1} {0}", "NEJ", DiagnosticSeverity.Warning, true), null, string.Join(", ", newList.Select(x => x.ToString())), propSymbol.Name)
);*/ );*/
@ -604,7 +604,7 @@ namespace AutoMapProperty
return sb.ToString(); return sb.ToString();
} }
} }
public static string GeneratePropertyTo(List<ClassToGenerate> otherClasses, string Key, ITypeSymbol FromType, ITypeSymbol ToType, bool nullable = true) public static string? GeneratePropertyTo(List<ClassToGenerate> otherClasses, string Key, ITypeSymbol FromType, ITypeSymbol ToType, bool nullable = true)
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.Append(Key).Append(@" ="); sb.Append(Key).Append(@" =");
@ -615,6 +615,9 @@ namespace AutoMapProperty
bool isArray = !SymbolEqualityComparer.Default.Equals(FromType, concreteFromType); bool isArray = !SymbolEqualityComparer.Default.Equals(FromType, concreteFromType);
if (concreteFromType.IsAbstract)
return null;
if (isArray) if (isArray)
{ {
sb.Append("(").Append(FromType).Append(@")(this.").Append(Key).Append(" != null ? "); sb.Append("(").Append(FromType).Append(@")(this.").Append(Key).Append(" != null ? ");
@ -657,7 +660,10 @@ namespace AutoMapProperty
{ {
if (Value.FromIsReadOnly) if (Value.FromIsReadOnly)
return null; return null;
retSb.Append(GeneratePropertyTo(otherClasses, Key, Value.FromType, Value.ToType, nullable)); var generated = GeneratePropertyTo(otherClasses, Key, Value.FromType, Value.ToType, nullable);
if (generated == null)
return null;
retSb.Append(generated);
} }
else else
{ {
@ -748,7 +754,7 @@ namespace ").Append(classToGenerate.Namespace).Append(@"
[System.CodeDom.Compiler.GeneratedCode(""AutoMapProperty"", ""1.0.0"")] [System.CodeDom.Compiler.GeneratedCode(""AutoMapProperty"", ""1.0.0"")]
public partial ").Append(classToGenerate.SourceContainer is ClassDeclarationSyntax ? "class " : "interface ").Append(classToGenerate.Name); public partial ").Append(classToGenerate.SourceContainer is ClassDeclarationSyntax ? "class " : "interface ").Append(classToGenerate.Name);
if (classToGenerate.SourceContainer is ClassDeclarationSyntax )//&& !classToGenerate.SourceContainer.Modifiers.Any(x => x.IsKind(SyntaxKind.AbstractKeyword))) if (classToGenerate.SourceContainer is ClassDeclarationSyntax)//&& !classToGenerate.SourceContainer.Modifiers.Any(x => x.IsKind(SyntaxKind.AbstractKeyword)))
{ {
sb.Append(": IAutomappedAttribute<").Append(classToGenerate.SourceContainer.Identifier).Append(",").Append(classToGenerate.Name).Append(">"); sb.Append(": IAutomappedAttribute<").Append(classToGenerate.SourceContainer.Identifier).Append(",").Append(classToGenerate.Name).Append(">");
sb.Append(", System.Collections.Generic.IEqualityComparer<").Append(classToGenerate.Name).Append(">"); sb.Append(", System.Collections.Generic.IEqualityComparer<").Append(classToGenerate.Name).Append(">");
@ -916,7 +922,9 @@ namespace ").Append(classToGenerate.Namespace).Append(@"
return null; return null;
{"); {");
foreach (var prop in classToGenerate.MappableProperties) foreach (var prop in classToGenerate.MappableProperties)
{ {/*
if (prop.Value.FromType.IsAbstract)
continue;*/
var property = GenerateCorrectToProperty(otherClasses, prop.Key, prop.Value); var property = GenerateCorrectToProperty(otherClasses, prop.Key, prop.Value);
if (property == null) if (property == null)
continue; continue;