コード例 #1
0
        private async Task <Document> GetEditAsync(
            Solution solution,
            INamespaceOrTypeSymbol destination,
            Func <SyntaxNode, TCodeGenerationOptions, IList <bool>?, CancellationToken, SyntaxNode> declarationTransform,
            CodeGenerationContext context,
            CancellationToken cancellationToken)
        {
            var(destinationDeclaration, availableIndices) =
                await this.FindMostRelevantDeclarationAsync(solution, destination, context, cancellationToken).ConfigureAwait(false);

            if (destinationDeclaration == null)
            {
                throw new ArgumentException(WorkspacesResources.Could_not_find_location_to_generation_symbol_into);
            }

            var destinationTree = destinationDeclaration.SyntaxTree;
            var oldDocument     = solution.GetRequiredDocument(destinationTree);
            var options         = (TCodeGenerationOptions)await CodeGenerationOptions.FromDocumentAsync(context, oldDocument, cancellationToken).ConfigureAwait(false);

            var transformedDeclaration = declarationTransform(destinationDeclaration, options, availableIndices, cancellationToken);

            var root = await destinationTree.GetRootAsync(cancellationToken).ConfigureAwait(false);

            var currentRoot = root.ReplaceNode(destinationDeclaration, transformedDeclaration);

            var newDocument = oldDocument.WithSyntaxRoot(currentRoot);

            if (context.AddImports)
            {
                newDocument = await ImportAdder.AddImportsFromSymbolAnnotationAsync(
                    newDocument,
                    await newDocument.GetOptionsAsync(cancellationToken).ConfigureAwait(false),
                    cancellationToken).ConfigureAwait(false);
            }

            return(newDocument);
        }
コード例 #2
0
 protected abstract CodeGenerationOptions WithContextImpl(CodeGenerationContext value);
コード例 #3
0
 public CodeGenerationOptions WithContext(CodeGenerationContext value)
 => WithContextImpl(value);
コード例 #4
0
        public static async ValueTask <CodeGenerationOptions> FromDocumentAsync(CodeGenerationContext context, Document document, CancellationToken cancellationToken)
        {
            var preferences = await CodeGenerationPreferences.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false);

            return(preferences.GetOptions(context));
        }
コード例 #5
0
 protected CodeGenerationOptions(CodeGenerationContext context)
 {
     Context = context;
 }
コード例 #6
0
 public abstract CodeGenerationOptions GetOptions(CodeGenerationContext context);
コード例 #7
0
 protected CodeGenerationContextInfo(CodeGenerationContext context)
 {
     Context = context;
 }
コード例 #8
0
 public static CodeGenerationOptions GetOptions(this ICodeGenerationService service, ParseOptions parseOptions, OptionSet documentOptions, CodeGenerationContext context)
 => service.GetPreferences(parseOptions, documentOptions).GetOptions(context);