Update AutoNotifyGenerator.cs
This commit is contained in:
Родитель
2667c5dd73
Коммит
00505a0391
|
@ -11,7 +11,8 @@ namespace Core2D.Generators;
|
|||
[Generator]
|
||||
public class AutoNotifyGenerator : ISourceGenerator
|
||||
{
|
||||
private const string AttributeText = @"// <auto-generated />
|
||||
private const string AttributeText = """
|
||||
// <auto-generated />
|
||||
#nullable enable
|
||||
using System;
|
||||
|
||||
|
@ -30,9 +31,11 @@ namespace Core2D.ViewModels
|
|||
|
||||
public bool IgnoreDataMember { get; set; } = false;
|
||||
}
|
||||
}";
|
||||
}
|
||||
""";
|
||||
|
||||
private const string ModifierText = @"// <auto-generated />
|
||||
private const string ModifierText = """
|
||||
// <auto-generated />
|
||||
namespace Core2D.ViewModels
|
||||
{
|
||||
public enum AccessModifier
|
||||
|
@ -43,7 +46,8 @@ namespace Core2D.ViewModels
|
|||
Private = 3,
|
||||
Internal = 4
|
||||
}
|
||||
}";
|
||||
}
|
||||
""";
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
// System.Diagnostics.Debugger.Launch();
|
||||
|
@ -79,11 +83,11 @@ namespace Core2D.ViewModels
|
|||
|
||||
List<IFieldSymbol> fieldSymbols = new();
|
||||
|
||||
foreach (FieldDeclarationSyntax field in receiver.CandidateFields)
|
||||
foreach (var field in receiver.CandidateFields)
|
||||
{
|
||||
var semanticModel = compilation.GetSemanticModel(field.SyntaxTree);
|
||||
|
||||
foreach (VariableDeclaratorSyntax variable in field.Declaration.Variables)
|
||||
foreach (var variable in field.Declaration.Variables)
|
||||
{
|
||||
var fieldSymbol = semanticModel.GetDeclaredSymbol(variable) as IFieldSymbol;
|
||||
if (fieldSymbol is null)
|
||||
|
@ -122,7 +126,7 @@ namespace Core2D.ViewModels
|
|||
return null;
|
||||
}
|
||||
|
||||
string namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
|
||||
var namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
|
||||
|
||||
var addNotifyInterface = !classSymbol.Interfaces.Contains(notifySymbol);
|
||||
|
||||
|
@ -185,7 +189,7 @@ namespace {namespaceName}
|
|||
{{");
|
||||
}
|
||||
|
||||
foreach (IFieldSymbol fieldSymbol in fields)
|
||||
foreach (var fieldSymbol in fields)
|
||||
{
|
||||
ProcessField(source, fieldSymbol, attributeSymbol);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче