|
| 1 | +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. |
| 2 | +// Licensed under the MIT License. See LICENSE in the project root for license information. |
| 3 | + |
| 4 | +namespace StyleCop.Analyzers.Lightup |
| 5 | +{ |
| 6 | + using System; |
| 7 | + using Microsoft.CodeAnalysis; |
| 8 | + using Microsoft.CodeAnalysis.CSharp.Syntax; |
| 9 | + |
| 10 | + internal static class UsingDirectiveSyntaxExtensions |
| 11 | + { |
| 12 | + private static readonly Func<UsingDirectiveSyntax, SyntaxToken> GlobalKeywordAccessor; |
| 13 | + private static readonly Func<UsingDirectiveSyntax, SyntaxToken> UnsafeKeywordAccessor; |
| 14 | + private static readonly Func<UsingDirectiveSyntax, TypeSyntax> NamespaceOrTypeAccessor; |
| 15 | + private static readonly Func<UsingDirectiveSyntax, SyntaxToken, UsingDirectiveSyntax> WithGlobalKeywordAccessor; |
| 16 | + private static readonly Func<UsingDirectiveSyntax, SyntaxToken, UsingDirectiveSyntax> WithUnsafeKeywordAccessor; |
| 17 | + private static readonly Func<UsingDirectiveSyntax, TypeSyntax, UsingDirectiveSyntax> WithNamespaceOrTypeAccessor; |
| 18 | + |
| 19 | + static UsingDirectiveSyntaxExtensions() |
| 20 | + { |
| 21 | + GlobalKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor<UsingDirectiveSyntax, SyntaxToken>(typeof(UsingDirectiveSyntax), nameof(GlobalKeyword)); |
| 22 | + UnsafeKeywordAccessor = LightupHelpers.CreateSyntaxPropertyAccessor<UsingDirectiveSyntax, SyntaxToken>(typeof(UsingDirectiveSyntax), nameof(UnsafeKeyword)); |
| 23 | + NamespaceOrTypeAccessor = LightupHelpers.CreateSyntaxPropertyAccessor<UsingDirectiveSyntax, TypeSyntax>(typeof(UsingDirectiveSyntax), nameof(NamespaceOrType)); |
| 24 | + WithGlobalKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor<UsingDirectiveSyntax, SyntaxToken>(typeof(UsingDirectiveSyntax), nameof(GlobalKeyword)); |
| 25 | + WithUnsafeKeywordAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor<UsingDirectiveSyntax, SyntaxToken>(typeof(UsingDirectiveSyntax), nameof(UnsafeKeyword)); |
| 26 | + WithNamespaceOrTypeAccessor = LightupHelpers.CreateSyntaxWithPropertyAccessor<UsingDirectiveSyntax, TypeSyntax>(typeof(UsingDirectiveSyntax), nameof(NamespaceOrType)); |
| 27 | + } |
| 28 | + |
| 29 | + public static SyntaxToken GlobalKeyword(this UsingDirectiveSyntax syntax) |
| 30 | + { |
| 31 | + return GlobalKeywordAccessor(syntax); |
| 32 | + } |
| 33 | + |
| 34 | + public static SyntaxToken UnsafeKeyword(this UsingDirectiveSyntax syntax) |
| 35 | + { |
| 36 | + return UnsafeKeywordAccessor(syntax); |
| 37 | + } |
| 38 | + |
| 39 | + public static TypeSyntax NamespaceOrType(this UsingDirectiveSyntax syntax) |
| 40 | + { |
| 41 | + return NamespaceOrTypeAccessor(syntax); |
| 42 | + } |
| 43 | + |
| 44 | + public static UsingDirectiveSyntax WithGlobalKeyword(this UsingDirectiveSyntax syntax, SyntaxToken globalKeyword) |
| 45 | + { |
| 46 | + return WithGlobalKeywordAccessor(syntax, globalKeyword); |
| 47 | + } |
| 48 | + |
| 49 | + public static UsingDirectiveSyntax WithUnsafeKeyword(this UsingDirectiveSyntax syntax, SyntaxToken unsafeKeyword) |
| 50 | + { |
| 51 | + return WithUnsafeKeywordAccessor(syntax, unsafeKeyword); |
| 52 | + } |
| 53 | + |
| 54 | + public static UsingDirectiveSyntax WithNamespaceOrType(this UsingDirectiveSyntax syntax, TypeSyntax namespaceOrType) |
| 55 | + { |
| 56 | + return WithNamespaceOrTypeAccessor(syntax, namespaceOrType); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments