本文整理汇总了C#中SyntaxTokenList类的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTokenList类的具体用法?C# SyntaxTokenList怎么用?C# SyntaxTokenList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SyntaxTokenList类属于命名空间,在下文中一共展示了SyntaxTokenList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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;
}
}
}
示例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);
}
示例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()));
}
}
示例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);
}
示例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(" "));
}
示例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()
));
}
}
示例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);
}
示例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");
}
}
示例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;
}
示例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);
}
示例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;
}
示例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));
示例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)));
}
}
}