public enum BlockType { None, Namespace, Class, Method, Property, Condition, Loop }
public void AnalyzeBlock(BlockSyntax node) { var blockType = BlockType.None; if (node.IsKind(SyntaxKind.NamespaceDeclaration)) { blockType = BlockType.Namespace; } else if (node.IsKind(SyntaxKind.ClassDeclaration)) { blockType = BlockType.Class; } else if (node.IsKind(SyntaxKind.MethodDeclaration)) { blockType = BlockType.Method; } else if (node.IsKind(SyntaxKind.PropertyDeclaration)) { blockType = BlockType.Property; } else if (node.IsKind(SyntaxKind.IfStatement) || node.IsKind(SyntaxKind.SwitchStatement)) { blockType = BlockType.Condition; } else if (node.IsKind(SyntaxKind.ForStatement) || node.IsKind(SyntaxKind.ForEachStatement) || node.IsKind(SyntaxKind.WhileStatement) || node.IsKind(SyntaxKind.DoStatement)) { blockType = BlockType.Loop; } // Do something with the BlockType }This example shows how BlockType can be used in code analysis to identify different types of blocks (e.g. namespace, class, method, etc.) and perform some actions based on it. 3. Package/library BlockType is a part of the Microsoft.CodeAnalysis.CSharp package/library, which provides C# language-specific APIs for the .NET Compiler Platform ("Roslyn").