private string ProcessClass(INamedTypeSymbol classSymbol, List <IFieldSymbol> fields, ISymbol attributeSymbol, ISymbol notifySymbol, GeneratorExecutionContext context) { if (!classSymbol.ContainingSymbol.Equals(classSymbol.ContainingNamespace, SymbolEqualityComparer.Default)) { return(null); //TODO: issue a diagnostic that it must be top level } var builder = new StringBuilder(); var indent = new IndentUtil(); var namespaceSymbol = classSymbol.ContainingNamespace; if (!namespaceSymbol.IsGlobalNamespace) { builder.AppendLine($@"namespace {namespaceSymbol.Name} {{"); indent.IncreaseSimple(); } builder.AppendLine($@" {indent.Value}public partial class {classSymbol.Name} : {notifySymbol.ToDisplayString()} {indent.Value}{{"); using var marker = indent.Increase(); // if the class doesn't implement INotifyPropertyChanged already, add it if (!classSymbol.Interfaces.Contains(notifySymbol)) { builder.Append($"{indent.Value}public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;"); } // create properties for each field foreach (IFieldSymbol fieldSymbol in fields) { ProcessField(builder, indent, fieldSymbol, attributeSymbol); } marker.Revert(); builder.Append($"{indent.Value}}}"); if (!namespaceSymbol.IsGlobalNamespace) { indent.Decrease(); builder.AppendLine("}"); } return(builder.ToString()); }
public void Dispose() { _util.Decrease(_count); }