本文整理汇总了C#中CSharpSyntaxNode.GetDirectives方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpSyntaxNode.GetDirectives方法的具体用法?C# CSharpSyntaxNode.GetDirectives怎么用?C# CSharpSyntaxNode.GetDirectives使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpSyntaxNode
的用法示例。
在下文中一共展示了CSharpSyntaxNode.GetDirectives方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyDirectivesSpecial
private void VerifyDirectivesSpecial(CSharpSyntaxNode node, params DirectiveInfo[] expected)
{
var directives = node.GetDirectives();
Assert.Equal(expected.Length, directives.Count);
List<SyntaxKind> actual = new List<SyntaxKind>();
foreach (var dt in directives)
{
actual.Add(dt.Kind());
}
int idx = 0;
foreach (var exp in expected)
{
Assert.Equal(exp.Kind, actual[idx]); // exact order
// need to know what to expected here
var dt = directives[idx++];
if (NodeStatus.IsActive == (exp.Status & NodeStatus.IsActive))
{
Assert.True(dt.IsActive);
}
else if (NodeStatus.IsNotActive == (exp.Status & NodeStatus.IsNotActive))
{
Assert.False(dt.IsActive);
}
if (NodeStatus.BranchTaken == (exp.Status & NodeStatus.BranchTaken))
{
Assert.True(((BranchingDirectiveTriviaSyntax)dt).BranchTaken);
}
else if (NodeStatus.NotBranchTaken == (exp.Status & NodeStatus.NotBranchTaken))
{
Assert.False(((BranchingDirectiveTriviaSyntax)dt).BranchTaken);
}
if (NodeStatus.TrueValue == (exp.Status & NodeStatus.TrueValue))
{
Assert.True(((ConditionalDirectiveTriviaSyntax)dt).ConditionValue);
}
else if (NodeStatus.FalseValue == (exp.Status & NodeStatus.FalseValue))
{
Assert.False(((ConditionalDirectiveTriviaSyntax)dt).ConditionValue);
}
switch (exp.Kind)
{
case SyntaxKind.DefineDirectiveTrivia:
if (null != exp.Text)
{
Assert.Equal(exp.Text, ((DefineDirectiveTriviaSyntax)dt).Name.ValueText); // Text
}
break;
case SyntaxKind.LineDirectiveTrivia:
var ld = dt as LineDirectiveTriviaSyntax;
// default number = 0 - no number
if (exp.Number == -1)
{
Assert.Equal(SyntaxKind.LineKeyword, ld.LineKeyword.Kind());
Assert.Equal(SyntaxKind.DefaultKeyword, ld.Line.Kind());
}
else if (exp.Number == -2)
{
Assert.Equal(SyntaxKind.LineKeyword, ld.LineKeyword.Kind());
Assert.Equal(SyntaxKind.HiddenKeyword, ld.Line.Kind());
}
else if (exp.Number == 0)
{
Assert.Equal(String.Empty, ld.Line.Text);
}
else if (exp.Number > 0)
{
Assert.Equal(exp.Number, ld.Line.Value); // Number
Assert.Equal(exp.Number, Int32.Parse(ld.Line.Text));
}
if (null == exp.Text)
{
Assert.Equal(SyntaxKind.None, ld.File.Kind());
}
else
{
Assert.NotEqual(SyntaxKind.None, ld.File.Kind());
Assert.Equal(exp.Text, ld.File.Value);
}
break;
} // switch
}
}
示例2: VerifyDirectivePragma
private void VerifyDirectivePragma(CSharpSyntaxNode node, PragmaInfo expected)
{
var directives = node.GetDirectives();
Assert.Equal(1, directives.Count);
var dt = directives[0];
Assert.Equal(expected.PragmaKind, directives[0].Kind());
if (dt is PragmaWarningDirectiveTriviaSyntax)
{
var pwd = (PragmaWarningDirectiveTriviaSyntax)dt;
Assert.Equal(SyntaxKind.PragmaKeyword, pwd.PragmaKeyword.Kind());
if (SyntaxKind.None == expected.WarningOrChecksumKind)
{
Assert.True(pwd.WarningKeyword.IsMissing);
}
else
{
Assert.Equal(SyntaxKind.WarningKeyword, pwd.WarningKeyword.Kind());
}
if (SyntaxKind.None == expected.DisableOrRestoreKind)
{
Assert.True(pwd.DisableOrRestoreKeyword.IsMissing);
}
else
{
Assert.Equal(expected.DisableOrRestoreKind, pwd.DisableOrRestoreKeyword.Kind());
}
if (expected.WarningList == null || expected.WarningList.Length == 0)
{
Assert.Equal(0, pwd.ErrorCodes.Count);
}
else
{
Assert.Equal(expected.WarningList.Length, pwd.ErrorCodes.Count);
int idx = 0;
foreach (var warningNumber in expected.WarningList)
{
var actualWarningNumber = pwd.ErrorCodes[idx++];
if (actualWarningNumber.Kind() == SyntaxKind.NumericLiteralExpression)
{
var token = (actualWarningNumber as LiteralExpressionSyntax).Token;
Assert.Equal(warningNumber, token.ValueText);
}
else if (actualWarningNumber.Kind() == SyntaxKind.IdentifierName)
{
var token = (actualWarningNumber as IdentifierNameSyntax).Identifier;
Assert.Equal(warningNumber, token.ValueText);
}
else
{
Assert.True(false, "Warning ID must be an identifier or numeric literal");
}
}
}
}
else if (dt is PragmaChecksumDirectiveTriviaSyntax)
{
var pcd = (PragmaChecksumDirectiveTriviaSyntax)dt;
Assert.Equal(SyntaxKind.PragmaKeyword, pcd.PragmaKeyword.Kind());
Assert.Equal(SyntaxKind.ChecksumKeyword, pcd.ChecksumKeyword.Kind()); // no missing
// always 3
Assert.Equal(3, expected.FileGuidByte.Length);
if (expected.FileGuidByte[0] == null)
{
Assert.True(pcd.File.IsMissing);
}
Assert.Equal(expected.FileGuidByte[0], pcd.File.Value);
if (expected.FileGuidByte[1] == null)
{
Assert.True(pcd.Guid.IsMissing);
}
Assert.Equal(expected.FileGuidByte[1], pcd.Guid.Value);
if (expected.FileGuidByte[2] == null)
{
Assert.True(pcd.Bytes.IsMissing);
}
Assert.Equal(expected.FileGuidByte[2], pcd.Bytes.Value);
}
else
{
throw new NotImplementedException(dt.Kind().ToString());
}
}
示例3: VerifyDirectives
private void VerifyDirectives(CSharpSyntaxNode node, params SyntaxKind[] expected)
{
var directives = node.GetDirectives();
Assert.Equal(expected.Length, directives.Count);
if (expected.Length == 0)
{
return;
}
List<SyntaxKind> actual = new List<SyntaxKind>();
foreach (var dt in directives)
{
actual.Add(dt.Kind());
}
int idx = 0;
foreach (var ek in expected)
{
// Assert.True(actualKinds.Contains(kind)); // no order
Assert.Equal(ek, actual[idx++]); // exact order
}
}