private static ConversionOperatorDeclarationSyntax GenerateConversionDeclarationWorker( IMethodSymbol method, CodeGenerationDestination destination, CodeGenerationOptions options) { var hasNoBody = !options.GenerateMethodBodies || method.IsExtern; var reusableSyntax = GetReuseableSyntaxNodeForSymbol<ConversionOperatorDeclarationSyntax>(method, options); if (reusableSyntax != null) { return reusableSyntax; } var operatorToken = SyntaxFactory.Token(SyntaxFacts.GetOperatorKind(method.MetadataName)); var keyword = method.MetadataName == WellKnownMemberNames.ImplicitConversionName ? SyntaxFactory.Token(SyntaxKind.ImplicitKeyword) : SyntaxFactory.Token(SyntaxKind.ExplicitKeyword); return SyntaxFactory.ConversionOperatorDeclaration( attributeLists: AttributeGenerator.GenerateAttributeLists(method.GetAttributes(), options), modifiers: GenerateModifiers(method), implicitOrExplicitKeyword: keyword, operatorKeyword: SyntaxFactory.Token(SyntaxKind.OperatorKeyword), type: method.ReturnType.GenerateTypeSyntax(), parameterList: ParameterGenerator.GenerateParameterList(method.Parameters, isExplicit: false, options: options), body: hasNoBody ? null : StatementGenerator.GenerateBlock(method), semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : new SyntaxToken()); }
public static MemberDeclarationSyntax GenerateNamedTypeDeclaration( ICodeGenerationService service, INamedTypeSymbol namedType, CodeGenerationDestination destination, CodeGenerationOptions options, CancellationToken cancellationToken) { options = options ?? CodeGenerationOptions.Default; var declaration = GetDeclarationSyntaxWithoutMembers(namedType, destination, options); if (namedType.IsComImport) { // If we're generating a ComImport type, then do not attempt to do any // reordering of members. options = options.With(autoInsertionLocation: false, sortMembers: false); } // If we are generating members then make sure to exclude properties that cannot be generated. // Reason: Calling AddProperty on a propertysymbol that can't be generated (like one with params) causes // the getter and setter to get generated instead. Since the list of members is going to include // the method symbols for the getter and setter, we don't want to generate them twice. declaration = options.GenerateMembers && namedType.TypeKind != TypeKind.Delegate ? service.AddMembers(declaration, GetMembers(namedType).Where(s => s.Kind != SymbolKind.Property || PropertyGenerator.CanBeGenerated((IPropertySymbol)s)), options, cancellationToken) : declaration; return AddCleanupAnnotationsTo(ConditionallyAddDocumentationCommentTo(declaration, namedType, options)); }
private static MethodDeclarationSyntax GenerateMethodDeclarationWorker( IMethodSymbol method, CodeGenerationDestination destination, CodeGenerationOptions options) { var hasNoBody = !options.GenerateMethodBodies || destination == CodeGenerationDestination.InterfaceType || method.IsAbstract; var explicitInterfaceSpecifier = GenerateExplicitInterfaceSpecifier(method.ExplicitInterfaceImplementations); var returnType = method.ReturnsByRef ? method.ReturnType.GenerateRefTypeSyntax() : method.ReturnType.GenerateTypeSyntax(); return AddCleanupAnnotationsTo(SyntaxFactory.MethodDeclaration( attributeLists: GenerateAttributes(method, options, explicitInterfaceSpecifier != null), modifiers: GenerateModifiers(method, destination, options), returnType: returnType, explicitInterfaceSpecifier: explicitInterfaceSpecifier, identifier: method.Name.ToIdentifierToken(), typeParameterList: GenerateTypeParameterList(method, options), parameterList: ParameterGenerator.GenerateParameterList(method.Parameters, explicitInterfaceSpecifier != null, options), constraintClauses: GenerateConstraintClauses(method), body: hasNoBody ? null : StatementGenerator.GenerateBlock(method), expressionBody: default(ArrowExpressionClauseSyntax), semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : new SyntaxToken())); }
internal static EnumDeclarationSyntax AddEnumMemberTo(EnumDeclarationSyntax destination, IFieldSymbol enumMember, CodeGenerationOptions options) { var members = new List<SyntaxNodeOrToken>(); members.AddRange(destination.Members.GetWithSeparators()); var member = GenerateEnumMemberDeclaration(enumMember, destination, options); if (members.Count == 0) { members.Add(member); } else if (members.LastOrDefault().CSharpKind() == SyntaxKind.CommaToken) { members.Add(member); members.Add(SyntaxFactory.Token(SyntaxKind.CommaToken)); } else { var lastMember = members.Last(); var trailingTrivia = lastMember.GetTrailingTrivia(); members[members.Count - 1] = lastMember.WithTrailingTrivia(); members.Add(SyntaxFactory.Token(SyntaxKind.CommaToken).WithTrailingTrivia(trailingTrivia)); members.Add(member); } return destination.EnsureOpenAndCloseBraceTokens() .WithMembers(SyntaxFactory.SeparatedList<EnumMemberDeclarationSyntax>(members)); }
private static OperatorDeclarationSyntax GenerateOperatorDeclarationWorker( IMethodSymbol method, CodeGenerationDestination destination, CodeGenerationOptions options) { var hasNoBody = !options.GenerateMethodBodies || method.IsExtern; var operatorSyntaxKind = SyntaxFacts.GetOperatorKind(method.MetadataName); if (operatorSyntaxKind == SyntaxKind.None) { throw new ArgumentException(string.Format(WorkspacesResources.Cannot_generate_code_for_unsupported_operator_0, method.Name), nameof(method)); } var operatorToken = SyntaxFactory.Token(operatorSyntaxKind); return SyntaxFactory.OperatorDeclaration( attributeLists: AttributeGenerator.GenerateAttributeLists(method.GetAttributes(), options), modifiers: GenerateModifiers(method), returnType: method.ReturnType.GenerateTypeSyntax(), operatorKeyword: SyntaxFactory.Token(SyntaxKind.OperatorKeyword), operatorToken: operatorToken, parameterList: ParameterGenerator.GenerateParameterList(method.Parameters, isExplicit: false, options: options), body: hasNoBody ? null : StatementGenerator.GenerateBlock(method), semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : new SyntaxToken()); }
internal static ConstructorDeclarationSyntax GenerateConstructorDeclaration( IMethodSymbol constructor, CodeGenerationDestination destination, CodeGenerationOptions options) { options = options ?? CodeGenerationOptions.Default; var reusableSyntax = GetReuseableSyntaxNodeForSymbol<ConstructorDeclarationSyntax>(constructor, options); if (reusableSyntax != null) { return reusableSyntax; } bool hasNoBody = !options.GenerateMethodBodies; var declaration = SyntaxFactory.ConstructorDeclaration( attributeLists: AttributeGenerator.GenerateAttributeLists(constructor.GetAttributes(), options), modifiers: GenerateModifiers(constructor, options), identifier: CodeGenerationConstructorInfo.GetTypeName(constructor).ToIdentifierToken(), parameterList: ParameterGenerator.GenerateParameterList(constructor.Parameters, isExplicit: false, options: options), initializer: GenerateConstructorInitializer(constructor), body: hasNoBody ? null : GenerateBlock(constructor), semicolonToken: hasNoBody ? SyntaxFactory.Token(SyntaxKind.SemicolonToken) : default(SyntaxToken)); return AddCleanupAnnotationsTo( ConditionallyAddDocumentationCommentTo(declaration, constructor, options)); }
public static BracketedParameterListSyntax GenerateBracketedParameterList( ImmutableArray<IParameterSymbol> parameterDefinitions, bool isExplicit, CodeGenerationOptions options) { return GenerateBracketedParameterList((IList<IParameterSymbol>)parameterDefinitions, isExplicit, options); }
public static TypeParameterListSyntax GenerateTypeParameterList( ImmutableArray<ITypeParameterSymbol> typeParameters, CodeGenerationOptions options) { return typeParameters.Length == 0 ? null : SyntaxFactory.TypeParameterList( SyntaxFactory.SeparatedList(typeParameters.Select(t => GenerateTypeParameter(t, options)))); }
internal static ConversionOperatorDeclarationSyntax GenerateConversionDeclaration( IMethodSymbol method, CodeGenerationDestination destination, CodeGenerationOptions options) { var declaration = GenerateConversionDeclarationWorker(method, destination, options); return AddCleanupAnnotationsTo(AddAnnotationsTo(method, ConditionallyAddDocumentationCommentTo(declaration, method, options))); }
public static ParameterListSyntax GenerateParameterList( IEnumerable<IParameterSymbol> parameterDefinitions, bool isExplicit, CodeGenerationOptions options) { var parameters = GetParameters(parameterDefinitions, isExplicit, options); return SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameters)); }
private static AttributeListSyntax GenerateAttributeDeclaration( AttributeData attribute, SyntaxToken? target, CodeGenerationOptions options) { var attributeSyntax = GenerateAttribute(attribute, options); return attributeSyntax == null ? null : SyntaxFactory.AttributeList( target.HasValue ? SyntaxFactory.AttributeTargetSpecifier(target.Value) : null, SyntaxFactory.SingletonSeparatedList(attributeSyntax)); }
internal static CompilationUnitSyntax AddMethodTo( CompilationUnitSyntax destination, IMethodSymbol method, CodeGenerationOptions options, IList<bool> availableIndices) { var declaration = GenerateMethodDeclaration(method, CodeGenerationDestination.CompilationUnit, options); var members = Insert(destination.Members, declaration, options, availableIndices, after: LastMethod); return destination.WithMembers(members.ToSyntaxList()); }
private static TypeParameterSyntax GenerateTypeParameter(ITypeParameterSymbol symbol, CodeGenerationOptions options) { var varianceKeyword = symbol.Variance == VarianceKind.In ? SyntaxFactory.Token(SyntaxKind.InKeyword) : symbol.Variance == VarianceKind.Out ? SyntaxFactory.Token(SyntaxKind.OutKeyword) : default(SyntaxToken); return SyntaxFactory.TypeParameter( AttributeGenerator.GenerateAttributeLists(symbol.GetAttributes(), options), varianceKeyword, symbol.Name.ToIdentifierToken()); }
public static MemberDeclarationSyntax UpdateNamedTypeDeclaration( ICodeGenerationService service, MemberDeclarationSyntax declaration, IList<ISymbol> newMembers, CodeGenerationOptions options, CancellationToken cancellationToken) { declaration = RemoveAllMembers(declaration); declaration = service.AddMembers(declaration, newMembers, options, cancellationToken); return AddCleanupAnnotationsTo(declaration); }
public static CompilationUnitSyntax AddNamedTypeTo( ICodeGenerationService service, CompilationUnitSyntax destination, INamedTypeSymbol namedType, CodeGenerationOptions options, IList<bool> availableIndices) { var declaration = GenerateNamedTypeDeclaration(service, namedType, CodeGenerationDestination.CompilationUnit, options); var members = Insert(destination.Members, declaration, options, availableIndices); return destination.WithMembers(members); }
public static SyntaxNode UpdateCompilationUnitOrNamespaceDeclaration( ICodeGenerationService service, SyntaxNode declaration, IList<ISymbol> newMembers, CodeGenerationOptions options, CancellationToken cancellationToken) { declaration = RemoveAllMembers(declaration); declaration = service.AddMembers(declaration, newMembers, options, cancellationToken); return AddCleanupAnnotationsTo(declaration); }
internal static CompilationUnitSyntax AddPropertyTo( CompilationUnitSyntax destination, IPropertySymbol property, CodeGenerationOptions options, IList<bool> availableIndices) { var declaration = GeneratePropertyOrIndexer(property, CodeGenerationDestination.CompilationUnit, options); var members = Insert(destination.Members, declaration, options, availableIndices, after: LastPropertyOrField, before: FirstMember); return destination.WithMembers(members); }
public static BracketedParameterListSyntax GenerateBracketedParameterList( IEnumerable<IParameterSymbol> parameterDefinitions, bool isExplicit, CodeGenerationOptions options) { // Bracketed parameter lists come from indexers. Those don't have type parameters, so we // could never have a typeParameterMapping. var parameters = GetParameters(parameterDefinitions, isExplicit, options); return SyntaxFactory.BracketedParameterList( parameters: SyntaxFactory.SeparatedList(parameters)); }
internal static TypeDeclarationSyntax AddConversionTo( TypeDeclarationSyntax destination, IMethodSymbol method, CodeGenerationOptions options, IList<bool> availableIndices) { var methodDeclaration = GenerateConversionDeclaration(method, GetDestination(destination), options); var members = Insert(destination.Members, methodDeclaration, options, availableIndices, after: LastOperator); return AddMembersTo(destination, members); }
public static TypeDeclarationSyntax AddNamedTypeTo( ICodeGenerationService service, TypeDeclarationSyntax destination, INamedTypeSymbol namedType, CodeGenerationOptions options, IList<bool> availableIndices) { var declaration = GenerateNamedTypeDeclaration(service, namedType, GetDestination(destination), options); var members = Insert(destination.Members, declaration, options, availableIndices); return AddMembersTo(destination, members); }
internal static NamespaceDeclarationSyntax AddMethodTo( NamespaceDeclarationSyntax destination, IMethodSymbol method, Workspace workspace, CodeGenerationOptions options, IList<bool> availableIndices) { var declaration = GenerateMethodDeclaration( method, CodeGenerationDestination.Namespace, workspace, options, destination?.SyntaxTree.Options ?? options.ParseOptions); var members = Insert(destination.Members, declaration, options, availableIndices, after: LastMethod); return destination.WithMembers(members.ToSyntaxList()); }
public static NamespaceDeclarationSyntax AddNamedTypeTo( ICodeGenerationService service, NamespaceDeclarationSyntax destination, INamedTypeSymbol namedType, CodeGenerationOptions options, IList<bool> availableIndices) { var declaration = GenerateNamedTypeDeclaration(service, namedType, CodeGenerationDestination.Namespace, options); var members = Insert(destination.Members, declaration, options, availableIndices); return ConditionallyAddFormattingAnnotationTo( destination.WithMembers(members), members); }
internal static TypeDeclarationSyntax AddMethodTo( TypeDeclarationSyntax destination, IMethodSymbol method, CodeGenerationOptions options, IList<bool> availableIndices) { var methodDeclaration = GenerateMethodDeclaration(method, GetDestination(destination), options); // Create a clone of the original type with the new method inserted. var members = Insert(destination.Members, methodDeclaration, options, availableIndices, after: LastMethod); return AddMembersTo(destination, members); }
internal static ParameterSyntax GetParameter(IParameterSymbol p, CodeGenerationOptions options, bool isExplicit, bool isFirstParam, bool seenOptional) { var reusableSyntax = GetReuseableSyntaxNodeForSymbol<ParameterSyntax>(p, options); if (reusableSyntax != null) { return reusableSyntax; } return SyntaxFactory.Parameter(p.Name.ToIdentifierToken()) .WithAttributeLists(GenerateAttributes(p, isExplicit, options)) .WithModifiers(GenerateModifiers(p, isFirstParam)) .WithType(p.Type.GenerateTypeSyntax()) .WithDefault(GenerateEqualsValueClause(p, isExplicit, seenOptional)); }
internal static CompilationUnitSyntax AddFieldTo( CompilationUnitSyntax destination, IFieldSymbol field, CodeGenerationOptions options, IList<bool> availableIndices) { var declaration = GenerateFieldDeclaration(field, CodeGenerationDestination.CompilationUnit, options); // Place the field after the last field or const, or at the start of the type // declaration. var members = Insert(destination.Members, declaration, options, availableIndices, after: m => LastField(m, declaration), before: FirstMember); return destination.WithMembers(members.ToSyntaxList()); }
internal static CompilationUnitSyntax AddEventTo( CompilationUnitSyntax destination, IEventSymbol @event, CodeGenerationOptions options, IList<bool> availableIndices) { var declaration = GenerateEventDeclaration(@event, CodeGenerationDestination.CompilationUnit, options); // Place the event depending on its shape. Field style events go with fields, property // style events go with properties. If there var members = Insert(destination.Members, declaration, options, availableIndices, after: list => AfterMember(list, declaration), before: list => BeforeMember(list, declaration)); return destination.WithMembers(members.ToSyntaxList()); }
internal static TypeDeclarationSyntax AddFieldTo( TypeDeclarationSyntax destination, IFieldSymbol field, CodeGenerationOptions options, IList<bool> availableIndices) { var declaration = GenerateFieldDeclaration(field, GetDestination(destination), options); // Place the field after the last field or const, or at the start of the type // declaration. var members = Insert(destination.Members, declaration, options, availableIndices, after: m => LastField(m, declaration), before: FirstMember); return AddMembersTo(destination, members); }
private static AttributeSyntax GenerateAttribute(AttributeData attribute, CodeGenerationOptions options) { if (!options.MergeAttributes) { var reusableSyntax = GetReuseableSyntaxNodeForAttribute<AttributeSyntax>(attribute, options); if (reusableSyntax != null) { return reusableSyntax; } } var attributeArguments = GenerateAttributeArgumentList(attribute); var nameSyntax = attribute.AttributeClass.GenerateTypeSyntax() as NameSyntax; return nameSyntax == null ? null : SyntaxFactory.Attribute(nameSyntax, attributeArguments); }
internal static TypeDeclarationSyntax AddConstructorTo( TypeDeclarationSyntax destination, IMethodSymbol constructor, CodeGenerationOptions options, IList<bool> availableIndices) { var constructorDeclaration = GenerateConstructorDeclaration(constructor, GetDestination(destination), options); // Generate after the last constructor, or after the last field, or at the start of the // type. var members = Insert(destination.Members, constructorDeclaration, options, availableIndices, after: LastConstructorOrField, before: FirstMember); return AddMembersTo(destination, members); }
internal static TypeDeclarationSyntax AddOperatorTo( TypeDeclarationSyntax destination, IMethodSymbol method, Workspace workspace, CodeGenerationOptions options, IList<bool> availableIndices) { var methodDeclaration = GenerateOperatorDeclaration( method, GetDestination(destination), workspace, options, destination?.SyntaxTree.Options ?? options.ParseOptions); var members = Insert(destination.Members, methodDeclaration, options, availableIndices, after: LastOperator); return AddMembersTo(destination, members); }
protected abstract TDeclarationNode AddMethod <TDeclarationNode>(TDeclarationNode destination, IMethodSymbol method, CodeGenerationOptions options, IList <bool> availableIndices) where TDeclarationNode : SyntaxNode;
public TDeclarationNode AddMembers <TDeclarationNode>(TDeclarationNode destination, IEnumerable <ISymbol> members, CodeGenerationOptions options, CancellationToken cancellationToken) where TDeclarationNode : SyntaxNode { return(AddMembers(destination, members, GetAvailableInsertionIndices(destination, cancellationToken), options ?? CodeGenerationOptions.Default, cancellationToken)); }
/// <summary> /// Create a new solution where the declaration of the destination symbol has an additional property of the same signature as the specified property symbol. /// Returns the document in the new solution where the destination symbol is declared. /// </summary> public static Task <Document> AddPropertyDeclarationAsync(Solution solution, INamedTypeSymbol destination, IPropertySymbol property, CodeGenerationOptions options = default(CodeGenerationOptions), CancellationToken cancellationToken = default(CancellationToken)) { return(GetCodeGenerationService(solution.Workspace, destination.Language).AddPropertyAsync(solution, destination, property, options, cancellationToken)); }
/// <summary> /// Returns a newly created event declaration node from the provided event. /// </summary> public static SyntaxNode CreateEventDeclaration(IEventSymbol @event, Workspace workspace, CodeGenerationDestination destination = CodeGenerationDestination.Unspecified, CodeGenerationOptions options = null) { return(GetCodeGenerationService(workspace, @event.Language).CreateEventDeclaration(@event, destination, options)); }
/// <summary> /// Create a new solution where the declaration of the destination symbol has additional members of the same signature as the specified member symbols. /// Returns the document in the new solution where the destination symbol is declared. /// </summary> public static Task <Document> AddMemberDeclarationsAsync(Solution solution, INamedTypeSymbol destination, IEnumerable <ISymbol> members, CodeGenerationOptions options = default(CodeGenerationOptions), CancellationToken cancellationToken = default(CancellationToken)) { return(GetCodeGenerationService(solution.Workspace, destination.Language).AddMembersAsync(solution, destination, members, options, cancellationToken)); }
/// <summary> /// Returns a newly created property declaration node from the provided property. /// </summary> public static SyntaxNode CreatePropertyDeclaration(IPropertySymbol property, Workspace workspace, CodeGenerationDestination destination = CodeGenerationDestination.Unspecified, CodeGenerationOptions options = null) { return(GetCodeGenerationService(workspace, property.Language).CreatePropertyDeclaration(property, destination, options)); }
public Task <Document> AddNamespaceAsync(Solution solution, INamespaceSymbol destination, INamespaceSymbol @namespace, CodeGenerationOptions options, CancellationToken cancellationToken) { return(GetEditAsync( solution, destination, (t, opts, ai, ct) => AddNamespace(t, @namespace, opts, ai, ct), options, new[] { @namespace }, cancellationToken)); }
public Task <Document> AddMethodAsync(Solution solution, INamedTypeSymbol destination, IMethodSymbol method, CodeGenerationOptions options, CancellationToken cancellationToken) { return(GetEditAsync( solution, destination, (t, opts, ai, ct) => AddMethod(t, method, opts, ai), options, new[] { method }, cancellationToken)); }
public Task <Document> AddMembersAsync(Solution solution, INamedTypeSymbol destination, IEnumerable <ISymbol> members, CodeGenerationOptions options, CancellationToken cancellationToken) { return(GetEditAsync( solution, destination, (t, opts, ai, ct) => AddMembers(t, members, ai, opts, ct), options, members, cancellationToken)); }
/// <summary> /// Removes the specified attribute node from the given declaration node. /// </summary> public static TDeclarationNode RemoveAttribute <TDeclarationNode>(TDeclarationNode destination, Workspace workspace, SyntaxNode attributeToRemove, CodeGenerationOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) where TDeclarationNode : SyntaxNode { return(GetCodeGenerationService(workspace, destination.Language).RemoveAttribute(destination, attributeToRemove, options ?? CodeGenerationOptions.Default, cancellationToken)); }
protected abstract TDeclarationNode AddProperty <TDeclarationNode>(TDeclarationNode destination, IPropertySymbol property, CodeGenerationOptions options, IList <bool> availableIndices) where TDeclarationNode : SyntaxNode;
public TDeclarationNode AddNamespace <TDeclarationNode>(TDeclarationNode destination, INamespaceSymbol @namespace, CodeGenerationOptions options, CancellationToken cancellationToken) where TDeclarationNode : SyntaxNode { return(AddNamespace(destination, @namespace, options ?? CodeGenerationOptions.Default, GetAvailableInsertionIndices(destination, cancellationToken), cancellationToken)); }
/// <summary> /// Create a new declaration node with an event declaration of the same signature as the specified symbol added to it. /// </summary> public static TDeclarationNode AddEventDeclaration <TDeclarationNode>(TDeclarationNode destination, IEventSymbol @event, Workspace workspace, CodeGenerationOptions options = default(CodeGenerationOptions)) where TDeclarationNode : SyntaxNode { return(GetCodeGenerationService(workspace, destination.Language).AddEvent(destination, @event, options)); }
public TDeclarationNode AddProperty <TDeclarationNode>(TDeclarationNode destination, IPropertySymbol property, CodeGenerationOptions options, CancellationToken cancellationToken) where TDeclarationNode : SyntaxNode { return(AddProperty(destination, property, options ?? CodeGenerationOptions.Default, GetAvailableInsertionIndices(destination, cancellationToken))); }
/// <summary> /// Returns a newly created namespace declaration node from the provided namespace. /// </summary> public static SyntaxNode CreateNamespaceDeclaration(INamespaceSymbol @namespace, Workspace workspace, CodeGenerationDestination destination = CodeGenerationDestination.Unspecified, CodeGenerationOptions options = null) { return(GetCodeGenerationService(workspace, @namespace.Language).CreateNamespaceDeclaration(@namespace, destination, options)); }
public Task <Document> AddPropertyAsync(Solution solution, INamedTypeSymbol destination, IPropertySymbol property, CodeGenerationOptions options, CancellationToken cancellationToken) { return(GetEditAsync( solution, destination, (t, opts, ai, ct) => AddProperty(t, property, opts, ai), options, new[] { property }, cancellationToken)); }
/// <summary> /// Returns a newly created method declaration node from the provided method. /// </summary> public static SyntaxNode CreateMethodDeclaration(IMethodSymbol method, Workspace workspace, CodeGenerationDestination destination = CodeGenerationDestination.Unspecified, CodeGenerationOptions options = null) { return(GetCodeGenerationService(workspace, method.Language).CreateMethodDeclaration(method, destination, options)); }
public Task <Document> AddFieldAsync(Solution solution, INamedTypeSymbol destination, IFieldSymbol field, CodeGenerationOptions options, CancellationToken cancellationToken) { return(GetEditAsync( solution, destination, (t, opts, ai, ct) => AddField(t, field, opts, ai), options, new[] { field }, cancellationToken)); }
/// <summary> /// Create a new solution where the declaration of the destination symbol has an additional namespace or type of the same signature as the specified namespace or type symbol. /// Returns the document in the new solution where the destination symbol is declared. /// </summary> public static Task <Document> AddNamespaceOrTypeDeclarationAsync(Solution solution, INamespaceSymbol destination, INamespaceOrTypeSymbol namespaceOrType, CodeGenerationOptions options = default(CodeGenerationOptions), CancellationToken cancellationToken = default(CancellationToken)) { return(GetCodeGenerationService(solution.Workspace, destination.Language).AddNamespaceOrTypeAsync(solution, destination, namespaceOrType, options, cancellationToken)); }
public TDeclarationNode AddMethod <TDeclarationNode>(TDeclarationNode destination, IMethodSymbol method, CodeGenerationOptions options, CancellationToken cancellationToken) where TDeclarationNode : SyntaxNode { return(AddMethod(destination, method, options ?? CodeGenerationOptions.Default, GetAvailableInsertionIndices(destination, cancellationToken))); }
public TDeclarationNode AddEvent <TDeclarationNode>(TDeclarationNode destination, IEventSymbol @event, CodeGenerationOptions options, CancellationToken cancellationToken) where TDeclarationNode : SyntaxNode { return(AddEvent(destination, @event, options ?? CodeGenerationOptions.Default, GetAvailableInsertionIndices(destination, cancellationToken))); }
/// <summary> /// Create a new declaration node with one or more statements added to its body. /// </summary> public static TDeclarationNode AddStatements <TDeclarationNode>(TDeclarationNode destinationMember, IEnumerable <SyntaxNode> statements, Workspace workspace, CodeGenerationOptions options = default(CodeGenerationOptions)) where TDeclarationNode : SyntaxNode { return(GetCodeGenerationService(workspace, destinationMember.Language).AddStatements(destinationMember, statements, options)); }
/// <summary> /// Create a new solution where the declaration of the destination symbol has an additional method of the same signature as the specified method symbol. /// Returns the document in the new solution where the destination symbol is declared. /// </summary> public static Task <Document> AddMethodDeclarationAsync(Solution solution, INamedTypeSymbol destination, IMethodSymbol method, CodeGenerationOptions options = default(CodeGenerationOptions), CancellationToken cancellationToken = default(CancellationToken)) { return(GetCodeGenerationService(solution.Workspace, destination.Language).AddMethodAsync(solution, destination, method, options, cancellationToken)); }
public static TDeclarationNode UpdateDeclarationAccessibility <TDeclarationNode>(TDeclarationNode destination, Workspace workspace, Accessibility newAccesibility, CodeGenerationOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) where TDeclarationNode : SyntaxNode { return(GetCodeGenerationService(workspace, destination.Language).UpdateDeclarationAccessibility(destination, newAccesibility, options ?? new CodeGenerationOptions(reuseSyntax: true), cancellationToken)); }
/// <summary> /// Create a new declaration node with a property declaration of the same signature as the specified symbol added to it. /// </summary> public static TDeclarationNode AddPropertyDeclaration <TDeclarationNode>(TDeclarationNode destination, IPropertySymbol property, Workspace workspace, CodeGenerationOptions options = default(CodeGenerationOptions)) where TDeclarationNode : SyntaxNode { return(GetCodeGenerationService(workspace, destination.Language).AddProperty(destination, property, options)); }
protected abstract TDeclarationNode AddEvent <TDeclarationNode>(TDeclarationNode destination, IEventSymbol @event, CodeGenerationOptions options, IList <bool> availableIndices) where TDeclarationNode : SyntaxNode;
public static TDeclarationNode UpdateDeclarationMembers <TDeclarationNode>(TDeclarationNode destination, Workspace workspace, IList <ISymbol> newMembers, CodeGenerationOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) where TDeclarationNode : SyntaxNode { return(GetCodeGenerationService(workspace, destination.Language).UpdateDeclarationMembers(destination, newMembers, options ?? new CodeGenerationOptions(reuseSyntax: true), cancellationToken)); }
/// <summary> /// Create a new declaration node with a method declaration of the same signature as the specified symbol added to it. /// </summary> public static TDeclarationNode AddMethodDeclaration <TDeclarationNode>(TDeclarationNode destination, IMethodSymbol method, Workspace workspace, CodeGenerationOptions options = default(CodeGenerationOptions)) where TDeclarationNode : SyntaxNode { return(GetCodeGenerationService(workspace, destination.Language).AddMethod(destination, method, options)); }
protected abstract TDeclarationNode AddNamespace <TDeclarationNode>(TDeclarationNode destination, INamespaceSymbol @namespace, CodeGenerationOptions options, IList <bool> availableIndices, CancellationToken cancellationToken) where TDeclarationNode : SyntaxNode;
public Task <Document> AddNamespaceOrTypeAsync(Solution solution, INamespaceSymbol destination, INamespaceOrTypeSymbol namespaceOrType, CodeGenerationOptions options, CancellationToken cancellationToken) { if (namespaceOrType == null) { throw new ArgumentNullException(nameof(namespaceOrType)); } if (namespaceOrType is INamespaceSymbol namespaceSymbol) { return(AddNamespaceAsync(solution, destination, namespaceSymbol, options, cancellationToken)); } else { return(AddNamedTypeAsync(solution, destination, (INamedTypeSymbol)namespaceOrType, options, cancellationToken)); } }