using System.Collections.Generic; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace CTA.WebForms.TagCodeBehindHandlers { public abstract class TagCodeBehindHandler { /// /// The expected type representation in the code behind for the control that /// this handler is tasked with handling. /// public string CodeBehindType { get; } /// /// The value of the ID attribute for the control that this handler is tasked with /// handling. /// public string IdValue { get; } /// /// Conversions that have been staged for code behind references to the control /// that this handler is tasked with handling. /// public ISet<(SyntaxNode input, SyntaxNode replacement)> StagedConversions; /// /// Initializes a new instance. /// /// The expected type representation in the code behind for the control that /// this handler is tasked with handling. /// The value of the ID attribute for the control that this handler is tasked with /// handling. public TagCodeBehindHandler(string codeBehindType, string idValue) { CodeBehindType = codeBehindType; IdValue = idValue; StagedConversions = new HashSet<(SyntaxNode, SyntaxNode)>(); } /// /// Stages conversions of any references to the attribute named to a /// new represenation as a generated bindable property. /// /// The semantic model that belongs to. /// The declaration syntax for the code behind being converted. /// The name of the attribute currently being converted as it will appear in /// the code behind. /// The converted source attribute value, should no /// code behind conversions be necessary. public abstract void StageCodeBehindConversionsForAttribute( SemanticModel semanticModel, ClassDeclarationSyntax classDeclaration, string codeBehindName, string convertedSourceValue); /// /// Stages removal operations for any unconvertable references to code behind attributes for this /// handler's node and does any other code behind reference related clean up. /// /// The semantic model that belongs to. /// The declaration syntax for the code behind being converted. public abstract void StageCleanUpForUnconvertableReferences( SemanticModel semanticModel, ClassDeclarationSyntax classDeclaration); /// /// Adds any members staged for addition to the code behind. /// /// The declaration syntax for the code behind being converted. /// The modified version of . public abstract ClassDeclarationSyntax PerformMemberAdditions(ClassDeclarationSyntax classDeclaration); /// /// Generates replacement text for an attribute assignment or /// a basic replacement, using a binding to a generated code behind /// property if one exists. /// /// The name of the attribute being converted as it will /// appear in the code behind. /// The attribute that the conversion result will be assigned to, /// if one exists, otherwise null. /// Replacement text for placeholder using a binding to a generated /// code behind property if one exists, otherwise null. public abstract string GetBindingIfExists(string codeBehindName, string targetAttribute); } }