本文整理汇总了C#中SyntaxNode.GetDirectives方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.GetDirectives方法的具体用法?C# SyntaxNode.GetDirectives怎么用?C# SyntaxNode.GetDirectives使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.GetDirectives方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyDirectivesSpecial
private void VerifyDirectivesSpecial(SyntaxNode node, params DirectiveInfo[] expected)
{
var directives = node.GetDirectives().ToList();
Assert.AreEqual(expected.Length, directives.Count);
var actual = new List<SyntaxKind>();
foreach (var dt in directives)
{
actual.Add(dt.Kind);
}
int idx = 0;
foreach (var exp in expected)
{
Assert.AreEqual(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.ObjectLikeDefineDirectiveTrivia:
if (null != exp.Text)
Assert.AreEqual(exp.Text, ((ObjectLikeDefineDirectiveTriviaSyntax) dt).Name.Text); // Text
break;
case SyntaxKind.FunctionLikeDefineDirectiveTrivia:
if (null != exp.Text)
Assert.AreEqual(exp.Text, ((FunctionLikeDefineDirectiveTriviaSyntax) dt).Name.Text); // Text
break;
case SyntaxKind.LineDirectiveTrivia:
var ld = dt as LineDirectiveTriviaSyntax;
// default number = 0 - no number
if (exp.Number == -1)
{
Assert.AreEqual(SyntaxKind.LineKeyword, ld.LineKeyword.Kind);
Assert.AreEqual(SyntaxKind.DefaultKeyword, ld.Line.Kind);
}
else if (exp.Number == -2)
{
Assert.AreEqual(SyntaxKind.LineKeyword, ld.LineKeyword.Kind);
//Assert.AreEqual(SyntaxKind.HiddenKeyword, ld.Line.Kind);
}
else if (exp.Number == 0)
{
Assert.AreEqual(String.Empty, ld.Line.Text);
}
else if (exp.Number > 0)
{
Assert.AreEqual(exp.Number, ld.Line.Value); // Number
Assert.AreEqual(exp.Number, Int32.Parse(ld.Line.Text));
}
if (null == exp.Text)
{
Assert.AreEqual(SyntaxKind.None, ld.File.Kind);
}
else
{
Assert.AreNotEqual(SyntaxKind.None, ld.File.Kind);
Assert.AreEqual(exp.Text, ld.File.Value);
}
break;
} // switch
}
}
示例2: VerifyDirectives
private void VerifyDirectives(SyntaxNode node, params SyntaxKind[] expected)
{
var directives = node.GetDirectives().ToList();
Assert.AreEqual(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.AreEqual(ek, actual[idx++]); // exact order
}
}