本文整理汇总了C#中SyntaxTokenList类的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTokenList类的具体用法?C# SyntaxTokenList怎么用?C# SyntaxTokenList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SyntaxTokenList类属于命名空间,在下文中一共展示了SyntaxTokenList类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: IsStaticMember
/// <summary>
/// Only valid for field/constructor/property/method
/// </summary>
/// <param name="syntax"></param>
/// <returns></returns>
public static bool IsStaticMember(this MemberDeclarationSyntax syntax)
{
SyntaxTokenList modifiers = new SyntaxTokenList();
switch (syntax.Kind())
{
case SyntaxKind.FieldDeclaration:
var field = syntax as FieldDeclarationSyntax;
modifiers = field.Modifiers;
break;
case SyntaxKind.PropertyDeclaration:
var property = syntax as PropertyDeclarationSyntax;
modifiers = property.Modifiers;
break;
case SyntaxKind.MethodDeclaration:
var method = syntax as MethodDeclarationSyntax;
modifiers = method.Modifiers;
break;
case SyntaxKind.ConstructorDeclaration:
var ctor = syntax as ConstructorDeclarationSyntax;
modifiers = ctor.Modifiers;
break;
}
foreach (var modifier in modifiers)
{
if (modifier.Kind() == SyntaxKind.StaticKeyword)
return true;
}
return false;
}
开发者ID:rexzh,项目名称:SharpJs,代码行数:37,代码来源:SyntaxExtensions.cs
示例2: MethodDeclaration
public static MethodDeclarationSyntax MethodDeclaration(
SyntaxList<AttributeListSyntax> attributeLists,
SyntaxTokenList modifiers,
TypeSyntax returnType,
ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier,
SyntaxToken identifier,
TypeParameterListSyntax typeParameterList,
ParameterListSyntax parameterList,
SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
BlockSyntax body,
SyntaxToken semicolonToken)
{
return SyntaxFactory.MethodDeclaration(
attributeLists,
modifiers,
default(SyntaxToken),
returnType,
explicitInterfaceSpecifier,
identifier,
typeParameterList,
parameterList,
constraintClauses,
body,
default(ArrowExpressionClauseSyntax),
semicolonToken);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:26,代码来源:MethodDeclarationSyntax.cs
示例3: AdjustAccessibility
static void AdjustAccessibility (SyntaxTokenList modifiers, ref Accessibility acc, ref bool isStatic, ref bool result)
{
isStatic = modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.StaticKeyword);
if (modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) &&
modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword)) {
acc = Accessibility.ProtectedOrInternal;
result = true;
return;
}
foreach (var mod in modifiers) {
if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.PublicKeyword) {
acc = Accessibility.Public;
result = true;
return;
}
if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.PrivateKeyword) {
acc = Accessibility.Private;
result = true;
return;
}
if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) {
acc = Accessibility.Protected;
result = true;
return;
}
if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword) {
acc = Accessibility.Internal;
result = true;
return;
}
}
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:33,代码来源:AstStockIcons.cs
示例4: CreateSpan
private static TextSpan CreateSpan(SyntaxTokenList startOpt, SyntaxNodeOrToken startFallbackOpt, SyntaxNodeOrToken endOpt)
{
Debug.Assert(startFallbackOpt != default(SyntaxNodeOrToken) || endOpt != default(SyntaxNodeOrToken));
int startPos;
if (startOpt.Count > 0)
{
startPos = startOpt.First().SpanStart;
}
else if (startFallbackOpt != default(SyntaxNodeOrToken))
{
startPos = startFallbackOpt.SpanStart;
}
else
{
startPos = endOpt.SpanStart;
}
int endPos;
if (endOpt != default(SyntaxNodeOrToken))
{
endPos = GetEndPosition(endOpt);
}
else
{
endPos = GetEndPosition(startFallbackOpt);
}
return TextSpan.FromBounds(startPos, endPos);
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:30,代码来源:LocalRewriter_SequencePoints.cs
示例5: HandleDefaultModifier
static void HandleDefaultModifier(SyntaxNodeAnalysisContext context, SyntaxTokenList modifiers, SyntaxKind defaultModifier)
{
var index = modifiers.IndexOf(defaultModifier);
if (index != -1)
{
context.ReportDiagnostic(Diagnostic.Create(Rule, modifiers[index].GetLocation()));
}
}
开发者ID:cincuranet,项目名称:ExplicitDefaultAccessModifiersAnalyzer,代码行数:8,代码来源:DiagnosticAnalyzer.cs
示例6: ChangeTypeAccessibilityInDocumentAsync
private static async Task<Document> ChangeTypeAccessibilityInDocumentAsync(Solution solution, SyntaxTokenList newAccessibilityModifiers, Location typeLocation, CancellationToken cancellationToken)
{
var document = solution.GetDocument(typeLocation.SourceTree);
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var newRoot = ChangeTypeAccessibilityInSyntaxRoot(syntaxRoot, newAccessibilityModifiers, typeLocation, cancellationToken);
return document.WithSyntaxRoot(newRoot);
}
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:9,代码来源:InconsistentAccessibilityCodeFixProvider.cs
示例7: TextAttribute
public static XmlTextAttributeSyntax TextAttribute(XmlNameSyntax name, SyntaxKind quoteKind, SyntaxTokenList textTokens)
{
return SyntaxFactory.XmlTextAttribute(
name,
SyntaxFactory.Token(quoteKind),
textTokens,
SyntaxFactory.Token(quoteKind))
.WithLeadingTrivia(SyntaxFactory.Whitespace(" "));
}
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:9,代码来源:XmlSyntaxFactory.cs
示例8: MarkUnsafe
void MarkUnsafe(SyntaxTokenList modifiers, bool isUnsafe)
{
var state = unsafeStateStack.Pop();
if (isUnsafe && !state.UseUnsafeConstructs)
{
ctx.ReportDiagnostic(Diagnostic.Create(
descriptor,
modifiers.First(m => m.IsKind(SyntaxKind.UnsafeKeyword)).GetLocation()
));
}
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:11,代码来源:RedundantUnsafeContextAnalyzer.cs
示例9: DelegateDeclaration
public static DelegateDeclarationSyntax DelegateDeclaration(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, SyntaxToken delegateKeyword, TypeSyntax returnType, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses, SyntaxToken semicolonToken)
{
return DelegateDeclaration(
attributeLists,
modifiers,
delegateKeyword,
refKeyword: default(SyntaxToken),
returnType: returnType,
identifier: identifier,
typeParameterList: typeParameterList,
parameterList: parameterList,
constraintClauses: constraintClauses,
semicolonToken: semicolonToken);
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:14,代码来源:DelegateDeclarationSyntax.cs
示例10: TypeDeclaration
public static TypeDeclarationSyntax TypeDeclaration(SyntaxKind kind, SyntaxList<AttributeListSyntax> attributes, SyntaxTokenList modifiers, SyntaxToken keyword, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, BaseListSyntax baseList, SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses, SyntaxToken openBraceToken, SyntaxList<MemberDeclarationSyntax> members, SyntaxToken closeBraceToken, SyntaxToken semicolonToken)
{
switch (kind)
{
case SyntaxKind.ClassDeclaration:
return SyntaxFactory.ClassDeclaration(attributes, modifiers, keyword, identifier, typeParameterList, baseList, constraintClauses, openBraceToken, members, closeBraceToken, semicolonToken);
case SyntaxKind.StructDeclaration:
return SyntaxFactory.StructDeclaration(attributes, modifiers, keyword, identifier, typeParameterList, baseList, constraintClauses, openBraceToken, members, closeBraceToken, semicolonToken);
case SyntaxKind.InterfaceDeclaration:
return SyntaxFactory.InterfaceDeclaration(attributes, modifiers, keyword, identifier, typeParameterList, baseList, constraintClauses, openBraceToken, members, closeBraceToken, semicolonToken);
default:
throw new ArgumentException("kind");
}
}
开发者ID:riversky,项目名称:roslyn,代码行数:14,代码来源:TypeDeclarationSyntax.cs
示例11: ReplaceModifiers
// This code was copied from the Roslyn code base (and slightly modified). It can be removed if
// TypeDeclarationSyntaxExtensions.WithModifiers is made public (Roslyn issue #2186)
private static TypeDeclarationSyntax ReplaceModifiers(TypeDeclarationSyntax node, SyntaxTokenList modifiers)
{
switch (node.Kind())
{
case SyntaxKind.ClassDeclaration:
return ((ClassDeclarationSyntax)node).WithModifiers(modifiers);
case SyntaxKind.InterfaceDeclaration:
return ((InterfaceDeclarationSyntax)node).WithModifiers(modifiers);
case SyntaxKind.StructDeclaration:
return ((StructDeclarationSyntax)node).WithModifiers(modifiers);
}
return node;
}
开发者ID:Noryoko,项目名称:StyleCopAnalyzers,代码行数:16,代码来源:SA1205CodeFixProvider.cs
示例12: PropertyDeclaration
public static PropertyDeclarationSyntax PropertyDeclaration(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody, EqualsValueClauseSyntax initializer, SyntaxToken semicolonToken)
{
return PropertyDeclaration(
attributeLists,
modifiers,
refKeyword: default(SyntaxToken),
type: type,
explicitInterfaceSpecifier: explicitInterfaceSpecifier,
identifier: identifier,
accessorList: accessorList,
expressionBody: expressionBody,
initializer: initializer,
semicolonToken: semicolonToken);
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:14,代码来源:PropertyDeclarationSyntax.cs
示例13: WithModifiers
public static TypeDeclarationSyntax WithModifiers(
this TypeDeclarationSyntax node, SyntaxTokenList modifiers)
{
switch (node.CSharpKind())
{
case SyntaxKind.ClassDeclaration:
return ((ClassDeclarationSyntax)node).WithModifiers(modifiers);
case SyntaxKind.InterfaceDeclaration:
return ((InterfaceDeclarationSyntax)node).WithModifiers(modifiers);
case SyntaxKind.StructDeclaration:
return ((StructDeclarationSyntax)node).WithModifiers(modifiers);
}
throw Contract.Unreachable;
}
开发者ID:riversky,项目名称:roslyn,代码行数:15,代码来源:TypeDeclarationSyntaxExtensions.cs
示例14: DestructorDeclaration
public static DestructorDeclarationSyntax DestructorDeclaration(
SyntaxList<AttributeListSyntax> attributeLists,
SyntaxTokenList modifiers,
SyntaxToken identifier,
ParameterListSyntax parameterList,
ArrowExpressionClauseSyntax expressionBody)
=> DestructorDeclaration(
attributeLists,
modifiers,
SyntaxFactory.Token(SyntaxKind.TildeToken),
identifier,
parameterList,
default(BlockSyntax),
expressionBody,
default(SyntaxToken));
开发者ID:XieShuquan,项目名称:roslyn,代码行数:15,代码来源:DestructorDeclarationSyntax.cs
示例15: ProcessAttribute
protected void ProcessAttribute(SyntaxNodeAnalysisContext context, SyntaxTokenList textTokens)
{
var token = textTokens.First();
if (token.Span.Length >= 2)
{
var text = token.Text;
if (text[1] == ':')
{
var location = Location.Create(token.SyntaxTree, textTokens.Span);
context.ReportDiagnostic(Diagnostic.Create(Rule, location, text.Substring(0, 2)));
}
}
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:15,代码来源:DoNotUseVerbatimCrefsAnalyzer.cs
示例16: WithModifiers
public static TypeDeclarationSyntax WithModifiers(
this TypeDeclarationSyntax node, SyntaxTokenList modifiers)
{
switch (node.Kind())
{
case SyntaxKind.ClassDeclaration:
return ((ClassDeclarationSyntax)node).WithModifiers(modifiers);
case SyntaxKind.InterfaceDeclaration:
return ((InterfaceDeclarationSyntax)node).WithModifiers(modifiers);
case SyntaxKind.StructDeclaration:
return ((StructDeclarationSyntax)node).WithModifiers(modifiers);
}
throw new InvalidOperationException ();
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:15,代码来源:TypeDeclarationSyntaxExtensions.cs
示例17: GetAccessLevel
/// <summary>Determines the access level for the given <paramref name="modifiers"/>.</summary>
/// <param name="modifiers">The modifiers.</param>
/// <returns>A <see cref="AccessLevel"/> value representing the access level.</returns>
internal static AccessLevel GetAccessLevel(SyntaxTokenList modifiers)
{
bool isProtected = false;
bool isInternal = false;
foreach (var modifier in modifiers)
{
switch (modifier.Kind())
{
case SyntaxKind.PublicKeyword:
return AccessLevel.Public;
case SyntaxKind.PrivateKeyword:
return AccessLevel.Private;
case SyntaxKind.InternalKeyword:
if (isProtected)
{
return AccessLevel.ProtectedInternal;
}
else
{
isInternal = true;
}
break;
case SyntaxKind.ProtectedKeyword:
if (isInternal)
{
return AccessLevel.ProtectedInternal;
}
else
{
isProtected = true;
}
break;
}
}
if (isProtected)
{
return AccessLevel.Protected;
}
else if (isInternal)
{
return AccessLevel.Internal;
}
return AccessLevel.NotSpecified;
}
开发者ID:Romanx,项目名称:StyleCopAnalyzers,代码行数:51,代码来源:AccessLevelHelper.cs
示例18: SyntaxTree
internal SyntaxTree(string sourceText,
SyntaxNode root,
SyntaxTokenList tokens,
IReadOnlyList<TextLineExtent> textLines,
IReadOnlyList<Diagnostic> diagnostics,
FileInfo fileInfo,
Encoding encoding) {
_sourceText = sourceText ?? String.Empty;
_root = root;
_fileInfo = fileInfo;
_encoding = encoding;
_diagnostics = diagnostics ?? Enumerable.Empty<Diagnostic>().ToList();
_tokens = tokens ?? new SyntaxTokenList();
_textLines = textLines ?? new List<TextLineExtent>();
}
开发者ID:csharper2010,项目名称:Nav.Language.Extensions,代码行数:16,代码来源:SyntaxTree.cs
示例19: ConstructorDeclaration
public static ConstructorDeclarationSyntax ConstructorDeclaration(
SyntaxList<AttributeListSyntax> attributeLists,
SyntaxTokenList modifiers,
SyntaxToken identifier,
ParameterListSyntax parameterList,
ConstructorInitializerSyntax initializer,
ArrowExpressionClauseSyntax expressionBody)
=> ConstructorDeclaration(
attributeLists,
modifiers,
identifier,
parameterList,
initializer,
default(BlockSyntax),
expressionBody,
default(SyntaxToken));
开发者ID:XieShuquan,项目名称:roslyn,代码行数:16,代码来源:ConstructorDeclarationSyntax.cs
示例20: AddPublicAccessModifierAsync
private async Task<Document> AddPublicAccessModifierAsync(Document document, InterfaceDeclarationSyntax interfaceDeclaration, CancellationToken cancellationToken)
{
SyntaxTokenList newModifiers = new SyntaxTokenList();
newModifiers = newModifiers.Add(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
newModifiers = newModifiers.AddRange(interfaceDeclaration.Modifiers.Where(x =>
!x.IsKind(SyntaxKind.ProtectedKeyword) &&
!x.IsKind(SyntaxKind.InternalKeyword) &&
!x.IsKind(SyntaxKind.PrivateKeyword))
);
InterfaceDeclarationSyntax newInterfaceDeclaration = interfaceDeclaration.WithModifiers(newModifiers);
SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken);
SyntaxNode newRoot = root.ReplaceNode(interfaceDeclaration, newInterfaceDeclaration);
return document.WithSyntaxRoot(newRoot);
}
开发者ID:vebaspect,项目名称:roslyn-analyzers,代码行数:17,代码来源:CodeFixProvider.cs
注:本文中的SyntaxTokenList类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论