You can use this Walker to discover the syntactic features of C # 6:
public class CSharp6FeaturesWalker : CSharpSyntaxWalker { public bool CSharp6Features { get; private set; } public CSharp6FeatureWalker() { } public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node) { if (node.ExpressionBody != null) { CSharp6Features = true; } else if (node.Initializer != null) { CSharp6Features = true; } base.VisitPropertyDeclaration(node); } public override void VisitMethodDeclaration(MethodDeclarationSyntax node) { if (node.ExpressionBody != null) { CSharp6Features = true; } base.VisitMethodDeclaration(node); } public override void VisitOperatorDeclaration(OperatorDeclarationSyntax node) { if (node.ExpressionBody != null) { CSharp6Features = true; } base.VisitOperatorDeclaration(node); } public override void VisitConversionOperatorDeclaration(ConversionOperatorDeclarationSyntax node) { if (node.ExpressionBody != null) { CSharp6Features = true; } base.VisitConversionOperatorDeclaration(node); } public override void VisitIndexerDeclaration(IndexerDeclarationSyntax node) { if (node.ExpressionBody != null) { CSharp6Features = true; } base.VisitIndexerDeclaration(node); } public override void VisitConditionalAccessExpression(ConditionalAccessExpressionSyntax node) { CSharp6Features = true; base.VisitConditionalAccessExpression(node); } public override void VisitInterpolatedStringExpression(InterpolatedStringExpressionSyntax node) { CSharp6Features = true; base.VisitInterpolatedStringExpression(node); } public override void VisitCatchFilterClause(CatchFilterClauseSyntax node) { CSharp6Features = true; base.VisitCatchFilterClause(node); } }
Unfortunately, it is impossible to determine whether a file written in version 6 or not based solely on syntax checks, depending on some functions, depends on content, such as the nameof operator (it can be either in a special way or in the usual way)
For testing C # 6 functions, you can use this file from the ANTLR grammar repository.
source share