Click or drag to resize

SyntaxGenerator Class



A language agnostic factory for creating syntax nodes. This API can be used to create language specific syntax nodes that are semantically similar between languages.
Inheritance Hierarchy
SystemObject
  Microsoft.CodeAnalysis.EditingSyntaxGenerator

Namespace:  Microsoft.CodeAnalysis.Editing
Assembly:  Microsoft.CodeAnalysis.Workspaces (in Microsoft.CodeAnalysis.Workspaces.dll) Version: 2.3.0-dev-56735-00. Commit Hash: <developer build>
Syntax
public abstract class SyntaxGenerator : ILanguageService

The SyntaxGenerator type exposes the following members.

Constructors
  NameDescription
Protected methodSyntaxGenerator
Initializes a new instance of the SyntaxGenerator class
Top
Methods
  NameDescription
Public methodAddAccessors
Public methodAddAttributeArguments
Public methodAddAttributes(SyntaxNode, SyntaxNode)
Creates a new instance of a declaration with the specified attributes added.
Public methodAddAttributes(SyntaxNode, IEnumerableT)
Public methodAddBaseType
Adds a base type to the declaration
Public methodAddEventHandler
Creates a statement that adds the given handler to the given event.
Public methodAddExpression
Creates an expression that denotes an addition operation.
Public methodAddInterfaceType
Adds an interface type to the declaration
Public methodAddMembers(SyntaxNode, SyntaxNode)
Creates a new instance of the declaration with the members added to the end.
Public methodAddMembers(SyntaxNode, IEnumerableT)
Public methodAddNamespaceImports(SyntaxNode, SyntaxNode)
Creates a new instance of the declaration with the namespace imports added.
Public methodAddNamespaceImports(SyntaxNode, IEnumerableT)
Public methodAddParameters
Public methodAddReturnAttributes(SyntaxNode, SyntaxNode)
Creates a new instance of a method declaration node with return attributes added.
Public methodAddReturnAttributes(SyntaxNode, IEnumerableT)
Public methodAddSwitchSections
Public methodArgument(SyntaxNode)
Creates a node that is an argument to an invocation.
Public methodArgument(RefKind, SyntaxNode)
Creates a node that is an argument to an invocation.
Public methodArgument(String, RefKind, SyntaxNode)
Creates a node that is an argument to an invocation.
Public methodArrayCreationExpression(SyntaxNode, SyntaxNode)
Creates an array creation expression for a single dimensional array of specified size.
Public methodArrayCreationExpression(SyntaxNode, IEnumerableT)
Public methodArrayTypeExpression
Creates an expression that denotes an array type.
Public methodAsPrivateInterfaceImplementation(SyntaxNode, SyntaxNode)
Converts method, property and indexer declarations into private interface implementations. This is equivalent to a C# explicit interface implementation (you can declare it for access via the interface, but cannot call it directly).
Public methodAsPrivateInterfaceImplementation(SyntaxNode, SyntaxNode, String)
Converts method, property and indexer declarations into private interface implementations. This is equivalent to a C# explicit interface implementation (you can declare it for access via the interface, but cannot call it directly).
Public methodAsPublicInterfaceImplementation(SyntaxNode, SyntaxNode)
Converts method, property and indexer declarations into public interface implementations. This is equivalent to an implicit C# interface implementation (you can access it via the interface or directly via the named member.)
Public methodAsPublicInterfaceImplementation(SyntaxNode, SyntaxNode, String)
Converts method, property and indexer declarations into public interface implementations. This is equivalent to an implicit C# interface implementation (you can access it via the interface or directly via the named member.)
Public methodAssignmentStatement
Creates an expression that denotes an assignment from the right argument to left argument.
Public methodAttribute(AttributeData)
Creates an attribute matching existing attribute data.
Public methodAttribute(String, SyntaxNode)
Creates an attribute.
Public methodAttribute(String, IEnumerableT)
Public methodAttribute(SyntaxNode, IEnumerableT)
Public methodAttributeArgument(SyntaxNode)
Creates an attribute argument.
Public methodAttributeArgument(String, SyntaxNode)
Creates an attribute argument.
Public methodAwaitExpression
Creates an await expression.
Public methodBaseExpression
Creates an expression that denotes the containing method's base-parameter.
Public methodBitwiseAndExpression
Creates an expression that denotes a bitwise-and operation.
Public methodBitwiseNotExpression
Creates an expression that denotes a bitwise-not operation
Public methodBitwiseOrExpression
Creates an expression that denotes a bitwise-or operation.
Public methodCastExpression(ITypeSymbol, SyntaxNode)
Creates an expression that denotes a type cast operation.
Public methodCastExpression(SyntaxNode, SyntaxNode)
Creates an expression that denotes a type cast operation.
Public methodCatchClause(ITypeSymbol, String, IEnumerableT)
Public methodCatchClause(SyntaxNode, String, IEnumerableT)
Public methodClassDeclaration
Public methodClearTriviaTNode
Creates a new instance of the node with the leading and trailing trivia removed and replaced with elastic markers.
Public methodCoalesceExpression
Creates an expression that denotes a coalesce operation.
Public methodCompilationUnit(IEnumerableT)
Public methodCompilationUnit(SyntaxNode)
Creates a compilation unit declaration
Public methodConditionalExpression
Creates an expression that denotes a conditional evaluation operation.
Public methodConstructorDeclaration(IMethodSymbol, IEnumerableT, Void)
Public methodConstructorDeclaration(String, IEnumerableT, Void, SyntaxNode, Accessibility, DeclarationModifiers)
Public methodConvertExpression(ITypeSymbol, SyntaxNode)
Creates an expression that denotes a type conversion operation.
Public methodConvertExpression(SyntaxNode, SyntaxNode)
Creates an expression that denotes a type conversion operation.
Public methodCustomEventDeclaration(IEventSymbol, IEnumerableT, Void)
Public methodCustomEventDeclaration(String, SyntaxNode, Accessibility, DeclarationModifiers, IEnumerableT, Void, SyntaxNode)
Public methodDeclaration
Creates a declaration matching an existing symbol.
Public methodDefaultExpression(ITypeSymbol)
Public methodDefaultExpression(SyntaxNode)
An expression that represents the default value of a type. This is typically a null value for reference types or a zero-filled value for value types.
Public methodDefaultSwitchSection
Public methodDelegateDeclaration
Public methodDivideExpression
Creates an expression that denotes a division operation.
Public methodDottedName
Creates a name expression from a dotted name string.
Public methodElementAccessExpression(SyntaxNode, SyntaxNode)
Creates an expression that access an element of an array or indexer.
Public methodElementAccessExpression(SyntaxNode, IEnumerableT)
Public methodEnumDeclaration
Public methodEnumMember
Creates an enum member
Public methodEventDeclaration(IEventSymbol)
Creates an event declaration from an existing event symbol
Public methodEventDeclaration(String, SyntaxNode, Accessibility, DeclarationModifiers)
Creates an event declaration.
Public methodExitSwitchStatement
Create a statement that exits a switch statement and continues after it.
Public methodExpressionStatement
Creates statement that allows an expression to execute in a statement context. This is typically an invocation or assignment expression.
Public methodFalseLiteralExpression
Creates an expression that denotes the boolean false literal.
Public methodFieldDeclaration(IFieldSymbol)
Creates a field declaration matching an existing field symbol.
Public methodFieldDeclaration(IFieldSymbol, SyntaxNode)
Creates a field declaration matching an existing field symbol.
Public methodFieldDeclaration(String, SyntaxNode, Accessibility, DeclarationModifiers, SyntaxNode)
Creates a field declaration.
Public methodGenericName(String, ITypeSymbol)
Creates an expression that denotes a generic identifier name.
Public methodGenericName(String, SyntaxNode)
Creates an expression that denotes a generic identifier name.
Public methodGenericName(String, IEnumerableT)
Public methodGetAccessibility
Gets the accessibility of the declaration.
Public methodGetAccessor
Gets the accessor of the specified kind for the declaration.
Public methodGetAccessors
Public methodGetAttributeArguments
Public methodGetAttributes
Public methodGetBaseAndInterfaceTypes
Public methodGetDeclaration(SyntaxNode)
Returns the node if it is a declaration, the immediate enclosing declaration if one exists, or null.
Public methodGetDeclaration(SyntaxNode, DeclarationKind)
Returns the enclosing declaration of the specified kind or null.
Public methodGetDeclarationKind
Gets the DeclarationKind for the declaration.
Public methodGetExpression
Gets the expression associated with the declaration.
Public methodStatic memberGetGenerator(Document)
Gets the SyntaxGenerator for the language corresponding to the document.
Public methodStatic memberGetGenerator(Project)
Gets the SyntaxGenerator for the language corresponding to the project.
Public methodStatic memberGetGenerator(Workspace, String)
Gets the SyntaxGenerator for the specified language.
Public methodGetGetAccessorStatements
Public methodGetMembers
Public methodGetModifiers
Gets the DeclarationModifiers for the declaration.
Public methodGetName
Gets the name of the declaration.
Public methodGetNamespaceImports
Public methodGetParameters
Public methodGetReturnAttributes
Public methodGetSetAccessorStatements
Public methodGetStatements
Public methodGetSwitchSections
Public methodGetType
Gets the type of the declaration.
Public methodGreaterThanExpression
Creates an expression that denotes a greater-than test operation.
Public methodGreaterThanOrEqualExpression
Creates an expression that denotes a greater-than-or-equal test operation.
Public methodIdentifierName
Creates an expression that denotes a simple identifier name.
Public methodIfStatement(SyntaxNode, IEnumerableT, Void)
Public methodIndexerDeclaration(IPropertySymbol, IEnumerableT, Void)
Public methodIndexerDeclaration(IEnumerableT, Void, SyntaxNode, SyntaxNode, Accessibility, DeclarationModifiers)
Protected methodIndexOfT
Public methodInsertAccessors
Public methodInsertAttributeArguments
Public methodInsertAttributes(SyntaxNode, Int32, SyntaxNode)
Creates a new instance of the declaration with the attributes inserted.
Public methodInsertAttributes(SyntaxNode, Int32, IEnumerableT)
Public methodInsertMembers(SyntaxNode, Int32, SyntaxNode)
Creates a new instance of the declaration with the members inserted.
Public methodInsertMembers(SyntaxNode, Int32, IEnumerableT)
Public methodInsertNamespaceImports(SyntaxNode, Int32, SyntaxNode)
Creates a new instance of the declaration with the namespace imports inserted.
Public methodInsertNamespaceImports(SyntaxNode, Int32, IEnumerableT)
Public methodInsertNodesAfter
Public methodInsertNodesBefore
Public methodInsertParameters
Public methodInsertReturnAttributes(SyntaxNode, Int32, SyntaxNode)
Creates a new instance of a method declaration with return attributes inserted.
Public methodInsertReturnAttributes(SyntaxNode, Int32, IEnumerableT)
Public methodInsertSwitchSections
Public methodInterfaceDeclaration
Public methodInvocationExpression(SyntaxNode, SyntaxNode)
Creates a invocation expression
Public methodInvocationExpression(SyntaxNode, IEnumerableT)
Public methodIsTypeExpression(SyntaxNode, ITypeSymbol)
Creates an expression that denotes an is-type-check operation.
Public methodIsTypeExpression(SyntaxNode, SyntaxNode)
Creates an expression that denotes an is-type-check operation.
Public methodLambdaParameter(String, ITypeSymbol)
Creates a lambda parameter.
Public methodLambdaParameter(String, SyntaxNode)
Creates a lambda parameter.
Public methodLessThanExpression
Creates an expression that denotes a less-than test operation.
Public methodLessThanOrEqualExpression
Creates an expression that denotes a less-than-or-equal test operation.
Public methodLiteralExpression
Creates a literal expression. This is typically numeric primitives, strings or chars.
Public methodLocalDeclarationStatement(String, SyntaxNode)
Creates a statement that declares a single local variable.
Public methodLocalDeclarationStatement(ITypeSymbol, String, SyntaxNode, Boolean)
Creates a statement that declares a single local variable.
Public methodLocalDeclarationStatement(SyntaxNode, String, SyntaxNode, Boolean)
Creates a statement that declares a single local variable.
Public methodLockStatement
Public methodLogicalAndExpression
Creates an expression that denotes a logical-and operation.
Public methodLogicalNotExpression
Creates an expression that denotes a logical not operation.
Public methodLogicalOrExpression
Creates an expression that denotes a logical-or operation.
Public methodMemberAccessExpression(SyntaxNode, SyntaxNode)
Creates a member access expression.
Public methodMemberAccessExpression(SyntaxNode, String)
Creates a member access expression.
Public methodMethodDeclaration(IMethodSymbol, IEnumerableT)
Public methodMethodDeclaration(String, IEnumerableT, Void, SyntaxNode, IEnumerableT, Void, String)
Public methodModuloExpression
Creates an expression that denotes a modulo operation.
Public methodMultiplyExpression
Creates an expression that denotes a multiplication operation.
Public methodNameOfExpression
Creates an nameof expression.
Public methodNamespaceDeclaration(String, SyntaxNode)
Creates a namespace declaration.
Public methodNamespaceDeclaration(String, IEnumerableT)
Public methodNamespaceDeclaration(SyntaxNode, SyntaxNode)
Creates a namespace declaration.
Public methodNamespaceDeclaration(SyntaxNode, IEnumerableT)
Public methodNamespaceImportDeclaration(String)
Creates a namespace import declaration.
Public methodNamespaceImportDeclaration(SyntaxNode)
Creates a namespace import declaration.
Public methodNegateExpression
Creates an expression that denotes a unary negation operation.
Public methodNullableTypeExpression
Creates an expression that denotes a nullable type.
Public methodNullLiteralExpression
Creates an expression that denotes the null literal.
Public methodObjectCreationExpression(ITypeSymbol, SyntaxNode)
Creates an object creation expression.
Public methodObjectCreationExpression(ITypeSymbol, IEnumerableT)
Public methodObjectCreationExpression(SyntaxNode, SyntaxNode)
Creates an object creation expression.
Public methodObjectCreationExpression(SyntaxNode, IEnumerableT)
Public methodOperatorDeclaration(IMethodSymbol, IEnumerableT)
Public methodOperatorDeclaration(OperatorKind, IEnumerableT, Void, SyntaxNode, SyntaxNode, Accessibility)
Public methodParameterDeclaration(IParameterSymbol, SyntaxNode)
Creates a parameter declaration matching an existing parameter symbol.
Public methodParameterDeclaration(String, SyntaxNode, SyntaxNode, RefKind)
Creates a parameter declaration.
Protected methodStatic memberPreserveTriviaTNode
Public methodPropertyDeclaration(IPropertySymbol, IEnumerableT, Void)
Public methodPropertyDeclaration(String, SyntaxNode, Accessibility, DeclarationModifiers, IEnumerableT, Void)
Public methodQualifiedName
Creates a name expression that denotes a qualified name. The left operand can be any name expression. The right operand can be either and identifier or generic name.
Public methodReferenceEqualsExpression
Creates an expression that denotes a reference-type equality test operation.
Public methodReferenceNotEqualsExpression
Creates an expression that denotes a reference-type inequality test operation.
Public methodRemoveAllAttributes
Removes all attributes from the declaration, including return attributes.
Public methodRemoveEventHandler
Creates a statement that removes the given handler from the given event.
Public methodRemoveNode(SyntaxNode, SyntaxNode)
Removes the node from the sub tree starting at the root.
Public methodRemoveNode(SyntaxNode, SyntaxNode, SyntaxRemoveOptions)
Removes the node from the sub tree starting at the root.
Public methodRemoveNodes
Protected methodStatic memberRemoveRangeTNode(SeparatedSyntaxListTNode, Int32, Int32)
Protected methodStatic memberRemoveRangeTNode(SyntaxListTNode, Int32, Int32)
Public methodReplaceNode
Replaces the node in the root's tree with the new node.
Protected methodStatic memberReplaceRange
Protected methodStatic memberReplaceWithTrivia(SyntaxNode, SyntaxNode, SyntaxNode)
Protected methodStatic memberReplaceWithTrivia(SyntaxNode, SyntaxToken, SyntaxToken)
Protected methodStatic memberReplaceWithTriviaTNode(SyntaxNode, TNode, FuncT, TResult)
Public methodReturnStatement
Creates a statement that can be used to return a value from a method body.
Public methodStructDeclaration
Public methodSubtractExpression
Creates an expression that denotes an subtraction operation.
Public methodSwitchSection(IEnumerableT, Void)
Public methodSwitchSection(SyntaxNode, IEnumerableT)
Public methodSwitchStatement(SyntaxNode, SyntaxNode)
Creates a switch statement that branches to individual sections based on the value of the specified expression.
Public methodSwitchStatement(SyntaxNode, IEnumerableT)
Public methodThisExpression
Creates an expression that denotes the containing method's this-parameter.
Public methodThrowExpression
Creates an expression that can be used to throw an exception.
Public methodThrowStatement
Creates a statement that can be used to throw an exception.
Public methodTrueLiteralExpression
Creates an expression that denotes the boolean true literal.
Public methodTryCastExpression(SyntaxNode, ITypeSymbol)
Creates an expression that denotes an try-cast operation.
Public methodTryCastExpression(SyntaxNode, SyntaxNode)
Creates an expression that denotes an try-cast operation.
Public methodTryCatchStatement(IEnumerableT, Void)
Public methodTryCatchStatement(IEnumerableT, Void, SyntaxNode)
Public methodTryFinallyStatement
Public methodTypedConstantExpression
Creates an expression for a typed constant.
Public methodTypeExpression(ITypeSymbol)
Creates an expression that denotes a type.
Public methodTypeExpression(SpecialType)
Creates an expression that denotes a special type name.
Public methodTypeExpression(ITypeSymbol, Boolean)
Creates an expression that denotes a type. If addImport is false, adds a DoNotAddImportsAnnotation which will prevent any imports or usings from being added for the type.
Public methodTypeOfExpression
Creates an expression that evaluates to the type at runtime.
Public methodUsingStatement(SyntaxNode, IEnumerableT)
Public methodUsingStatement(String, SyntaxNode, IEnumerableT)
Public methodUsingStatement(SyntaxNode, String, SyntaxNode, IEnumerableT)
Public methodValueEqualsExpression
Creates an expression that denotes a value-type equality test operation.
Public methodValueNotEqualsExpression
Creates an expression that denotes a value-type inequality test operation.
Public methodValueReturningLambdaExpression(IEnumerableT)
Public methodValueReturningLambdaExpression(SyntaxNode)
Creates an expression that declares a zero parameter value returning lambda expression.
Public methodValueReturningLambdaExpression(IEnumerableT, Void)
Public methodValueReturningLambdaExpression(String, SyntaxNode)
Creates an expression that declares a single parameter value returning lambda expression.
Public methodValueReturningLambdaExpression(String, IEnumerableT)
Public methodVoidReturningLambdaExpression(IEnumerableT)
Public methodVoidReturningLambdaExpression(SyntaxNode)
Creates an expression that declares a zero parameter void returning lambda expression.
Public methodVoidReturningLambdaExpression(IEnumerableT, Void)
Public methodVoidReturningLambdaExpression(String, SyntaxNode)
Creates an expression that declares a single parameter void returning lambda expression.
Public methodVoidReturningLambdaExpression(String, IEnumerableT)
Public methodWhileStatement
Public methodWithAccessibility
Changes the accessibility of the declaration.
Public methodWithExpression
Changes the expression associated with the declaration.
Public methodWithGetAccessorStatements
Public methodWithModifiers
Changes the DeclarationModifiers for the declaration.
Public methodWithName
Changes the name of the declaration.
Public methodWithSetAccessorStatements
Public methodWithStatements
Public methodWithType
Changes the type of the declaration.
Public methodWithTypeArguments(SyntaxNode, SyntaxNode)
Converts an expression that ends in a name into an expression that ends in a generic name. If the expression already ends in a generic name, the new type arguments are used instead.
Public methodWithTypeArguments(SyntaxNode, IEnumerableT)
Public methodWithTypeConstraint(SyntaxNode, String, SyntaxNode)
Adds a type constraint to a type parameter of a declaration.
Public methodWithTypeConstraint(SyntaxNode, String, SpecialTypeConstraintKind, SyntaxNode)
Adds a type constraint to a type parameter of a declaration.
Public methodWithTypeConstraint(SyntaxNode, String, SpecialTypeConstraintKind, IEnumerableT)
Public methodWithTypeParameters(SyntaxNode, IEnumerableT)
Public methodWithTypeParameters(SyntaxNode, String)
Converts a declaration (method, class, etc) into a declaration with type parameters.
Top
Fields
  NameDescription
Public fieldStatic memberDefaultRemoveOptions
Top
See Also