本文整理汇总了C#中this.CSharpKind方法的典型用法代码示例。如果您正苦于以下问题:C# this.CSharpKind方法的具体用法?C# this.CSharpKind怎么用?C# this.CSharpKind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.CSharpKind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNameToken
public static SyntaxToken GetNameToken(this NameSyntax nameSyntax)
{
while (true)
{
if (nameSyntax.CSharpKind() == SyntaxKind.IdentifierName)
{
return ((IdentifierNameSyntax)nameSyntax).Identifier;
}
else if (nameSyntax.CSharpKind() == SyntaxKind.QualifiedName)
{
nameSyntax = ((QualifiedNameSyntax)nameSyntax).Right;
}
else if (nameSyntax.CSharpKind() == SyntaxKind.GenericName)
{
return ((GenericNameSyntax)nameSyntax).Identifier;
}
else if (nameSyntax.CSharpKind() == SyntaxKind.AliasQualifiedName)
{
nameSyntax = ((AliasQualifiedNameSyntax)nameSyntax).Name;
}
else
{
throw new NotSupportedException();
}
}
}
示例2: IsLiteral
public static bool IsLiteral(this SyntaxToken token)
{
return token.CSharpKind() == SyntaxKind.CharacterLiteralToken
|| token.CSharpKind() == SyntaxKind.FalseKeyword
|| token.CSharpKind() == SyntaxKind.NumericLiteralToken
|| token.CSharpKind() == SyntaxKind.StringLiteralToken
|| token.CSharpKind() == SyntaxKind.TrueKeyword;
}
示例3: GetCommentText
public static string GetCommentText(this SyntaxTrivia trivia)
{
var commentText = trivia.ToString();
if (trivia.CSharpKind() == SyntaxKind.SingleLineCommentTrivia)
{
if (commentText.StartsWith("//"))
{
commentText = commentText.Substring(2);
}
return commentText.TrimStart();
}
else if (trivia.CSharpKind() == SyntaxKind.MultiLineCommentTrivia)
{
var textBuilder = new StringBuilder();
if (commentText.EndsWith("*/"))
{
commentText = commentText.Substring(0, commentText.Length - 2);
}
if (commentText.StartsWith("/*"))
{
commentText = commentText.Substring(2);
}
commentText = commentText.Trim();
var newLine = Environment.NewLine;
var lines = commentText.Split(new[] { newLine }, StringSplitOptions.None);
foreach (var line in lines)
{
var trimmedLine = line.Trim();
// Note: we trim leading '*' characters in multi-line comments.
// If the '*' was intentional, sorry, it's gone.
if (trimmedLine.StartsWith("*"))
{
trimmedLine = trimmedLine.TrimStart('*');
trimmedLine = trimmedLine.TrimStart();
}
textBuilder.AppendLine(trimmedLine);
}
// remove last line break
textBuilder.Remove(textBuilder.Length - newLine.Length, newLine.Length);
return textBuilder.ToString();
}
else
{
throw new InvalidOperationException();
}
}
示例4: GetNameToken
public static SyntaxToken GetNameToken(this MemberDeclarationSyntax member)
{
if (member != null)
{
switch (member.CSharpKind())
{
case SyntaxKind.EnumDeclaration:
return ((EnumDeclarationSyntax)member).Identifier;
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.StructDeclaration:
return ((TypeDeclarationSyntax)member).Identifier;
case SyntaxKind.DelegateDeclaration:
return ((DelegateDeclarationSyntax)member).Identifier;
case SyntaxKind.FieldDeclaration:
return ((FieldDeclarationSyntax)member).Declaration.Variables.First().Identifier;
case SyntaxKind.EventFieldDeclaration:
return ((EventFieldDeclarationSyntax)member).Declaration.Variables.First().Identifier;
case SyntaxKind.PropertyDeclaration:
return ((PropertyDeclarationSyntax)member).Identifier;
case SyntaxKind.EventDeclaration:
return ((EventDeclarationSyntax)member).Identifier;
case SyntaxKind.MethodDeclaration:
return ((MethodDeclarationSyntax)member).Identifier;
}
}
// Constructors, destructors, indexers and operators don't have names.
return default(SyntaxToken);
}
示例5: MatchesKind
public static bool MatchesKind(this SyntaxNode node, params SyntaxKind[] kinds)
{
if (node == null)
{
return false;
}
return kinds.Contains(node.CSharpKind());
}
示例6: IsCompleteMultiLineComment
public static bool IsCompleteMultiLineComment(this SyntaxTrivia trivia)
{
if (trivia.CSharpKind() != SyntaxKind.MultiLineCommentTrivia)
{
return false;
}
var text = trivia.ToFullString();
return text.Length >= 4
&& text[text.Length - 1] == '/'
&& text[text.Length - 2] == '*';
}
示例7: WithParameters
public static BaseParameterListSyntax WithParameters(
this BaseParameterListSyntax parameterList,
SeparatedSyntaxList<ParameterSyntax> parameters)
{
switch (parameterList.CSharpKind())
{
case SyntaxKind.BracketedParameterList:
return ((BracketedParameterListSyntax)parameterList).WithParameters(parameters);
case SyntaxKind.ParameterList:
return ((ParameterListSyntax)parameterList).WithParameters(parameters);
}
throw Contract.Unreachable;
}
示例8: GetCloseToken
public static SyntaxToken GetCloseToken(this BaseArgumentListSyntax node)
{
if (node != null)
{
switch (node.CSharpKind())
{
case SyntaxKind.ArgumentList:
return ((ArgumentListSyntax)node).CloseParenToken;
case SyntaxKind.BracketedArgumentList:
return ((BracketedArgumentListSyntax)node).CloseBracketToken;
}
}
return default(SyntaxToken);
}
示例9: GetKind
public static string GetKind(this SyntaxNode node)
{
var kind = string.Empty;
if (node.Language == LanguageNames.CSharp)
{
kind = node.CSharpKind().ToString();
}
else
{
kind = node.VisualBasicKind().ToString();
}
return kind;
}
示例10: AddMembers
public static TypeDeclarationSyntax AddMembers(
this TypeDeclarationSyntax node, params MemberDeclarationSyntax[] members)
{
switch (node.CSharpKind())
{
case SyntaxKind.ClassDeclaration:
return ((ClassDeclarationSyntax)node).AddMembers(members);
case SyntaxKind.InterfaceDeclaration:
return ((InterfaceDeclarationSyntax)node).AddMembers(members);
case SyntaxKind.StructDeclaration:
return ((StructDeclarationSyntax)node).AddMembers(members);
}
throw Contract.Unreachable;
}
示例11: 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;
}
示例12: WithAttributeLists
public static TypeDeclarationSyntax WithAttributeLists(
this TypeDeclarationSyntax node, SyntaxList<AttributeListSyntax> attributes)
{
switch (node.CSharpKind())
{
case SyntaxKind.ClassDeclaration:
return ((ClassDeclarationSyntax)node).WithAttributeLists(attributes);
case SyntaxKind.InterfaceDeclaration:
return ((InterfaceDeclarationSyntax)node).WithAttributeLists(attributes);
case SyntaxKind.StructDeclaration:
return ((StructDeclarationSyntax)node).WithAttributeLists(attributes);
}
throw Contract.Unreachable;
}
示例13: GetAttributes
public static SyntaxList<AttributeListSyntax> GetAttributes(this MemberDeclarationSyntax member)
{
if (member != null)
{
switch (member.CSharpKind())
{
case SyntaxKind.EnumDeclaration:
return ((EnumDeclarationSyntax)member).AttributeLists;
case SyntaxKind.EnumMemberDeclaration:
return ((EnumMemberDeclarationSyntax)member).AttributeLists;
case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.StructDeclaration:
return ((TypeDeclarationSyntax)member).AttributeLists;
case SyntaxKind.DelegateDeclaration:
return ((DelegateDeclarationSyntax)member).AttributeLists;
case SyntaxKind.FieldDeclaration:
return ((FieldDeclarationSyntax)member).AttributeLists;
case SyntaxKind.EventFieldDeclaration:
return ((EventFieldDeclarationSyntax)member).AttributeLists;
case SyntaxKind.ConstructorDeclaration:
return ((ConstructorDeclarationSyntax)member).AttributeLists;
case SyntaxKind.DestructorDeclaration:
return ((DestructorDeclarationSyntax)member).AttributeLists;
case SyntaxKind.PropertyDeclaration:
return ((PropertyDeclarationSyntax)member).AttributeLists;
case SyntaxKind.EventDeclaration:
return ((EventDeclarationSyntax)member).AttributeLists;
case SyntaxKind.IndexerDeclaration:
return ((IndexerDeclarationSyntax)member).AttributeLists;
case SyntaxKind.OperatorDeclaration:
return ((OperatorDeclarationSyntax)member).AttributeLists;
case SyntaxKind.ConversionOperatorDeclaration:
return ((ConversionOperatorDeclarationSyntax)member).AttributeLists;
case SyntaxKind.MethodDeclaration:
return ((MethodDeclarationSyntax)member).AttributeLists;
case SyntaxKind.IncompleteMember:
return ((IncompleteMemberSyntax)member).AttributeLists;
}
}
return SyntaxFactory.List<AttributeListSyntax>();
}
示例14: IsCompoundAssignExpression
public static bool IsCompoundAssignExpression(this BinaryExpressionSyntax binaryExpression)
{
if (binaryExpression != null)
{
switch (binaryExpression.CSharpKind())
{
case SyntaxKind.AddAssignmentExpression:
case SyntaxKind.SubtractAssignmentExpression:
case SyntaxKind.MultiplyAssignmentExpression:
case SyntaxKind.DivideAssignmentExpression:
case SyntaxKind.ModuloAssignmentExpression:
case SyntaxKind.AndAssignmentExpression:
case SyntaxKind.ExclusiveOrAssignmentExpression:
case SyntaxKind.OrAssignmentExpression:
case SyntaxKind.LeftShiftAssignmentExpression:
case SyntaxKind.RightShiftAssignmentExpression:
return true;
}
}
return false;
}
示例15: IsCloseParenInArgumentList
public static bool IsCloseParenInArgumentList(this SyntaxToken token)
{
return token.CSharpKind() == SyntaxKind.CloseParenToken && token.Parent.CSharpKind() == SyntaxKind.ArgumentList;
}