public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var node = root.FindNode(context.Span); var attributeSyntax = node.TryCast().To <AttributeSyntax>() .ValueOrMaybe(() => node.Parent.TryCast().To <AttributeSyntax>()); var attributeNameSyntax = attributeSyntax .ChainValue(x => x.Name.TryCast().To <IdentifierNameSyntax>()); if (attributeNameSyntax.HasValueAnd(x => x.Identifier.Text.EqualsAny("CreateMatchMethods", "CreateMatchMethodsAttribute"))) { var action = CodeAction.Create( "Create Match methods", c => MatchCreation.CreateMatchMethods(context.Document, attributeSyntax.GetValue(), root, c)); context.RegisterRefactoring(action); } if (attributeNameSyntax.HasValueAnd(x => x.Identifier.Text.EqualsAny("CreateWithMethods", "CreateWithMethodsAttribute"))) { var action = CodeAction.Create( "Create With methods", c => WithMethodCreation.CreateWithMethods(context.Document, attributeSyntax.GetValue(), root, c)); context.RegisterRefactoring(action); } }
public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var node = root.FindNode(context.Span); var attributeSyntax = node.TryCast().To <AttributeSyntax>() .ValueOrMaybe(() => node.Parent.TryCast().To <AttributeSyntax>()); if (attributeSyntax.HasValueAnd(Utilities.IsCreateMatchMethodsAttribute)) { var action = CodeAction.Create( "Create Match methods", c => MatchCreation.CreateMatchMethods(context.Document, attributeSyntax.GetValue(), root, c)); context.RegisterRefactoring(action); } if (attributeSyntax.HasValueAnd(Utilities.IsCreateWithMethodsAttribute)) { var action = CodeAction.Create( "Create With methods", c => WithMethodCreation.CreateWithMethods(context.Document, attributeSyntax.GetValue(), root, c)); context.RegisterRefactoring(action); } var classSyntax = node.TryCast().To <ClassDeclarationSyntax>().If(x => !x.IsStatic()); if (classSyntax.HasValue) { var createMatchMethodsAction = CodeAction.Create( "Create Match methods", c => MatchCreation.CreateMatchMethods(context.Document, classSyntax.GetValue(), root, c)); context.RegisterRefactoring(createMatchMethodsAction); var createWithMethodsAction = CodeAction.Create( "Create With methods", c => WithMethodCreation.CreateWithMethods(context.Document, classSyntax.GetValue(), root, c)); context.RegisterRefactoring(createWithMethodsAction); } }