Example #1
0
        public static void Borrow()
        {
            var tree = CSharpSyntaxTree.ParseText(@"
namespace N
{
    using static NUnit.Framework.Assert;

    public class C
    {
        public C()
        {
            AreEqual(1, 1);
        }
    }
}");

            using (var walker = UsingStaticWalker.Borrow(tree))
            {
                CollectionAssert.AreEqual(new[] { "using static NUnit.Framework.Assert;" }, walker.UsingDirectives.Select(x => x.ToString()));
            }

            using (var walker = UsingStaticWalker.Borrow(tree.GetRoot(CancellationToken.None)))
            {
                CollectionAssert.AreEqual(new[] { "using static NUnit.Framework.Assert;" }, walker.UsingDirectives.Select(x => x.ToString()));
            }
        }
Example #2
0
        public static void TryGetForType()
        {
            var tree = CSharpSyntaxTree.ParseText(@"
namespace N
{
    using static NUnit.Framework.Assert;

    public class C
    {
        public C()
        {
            A.AreEqual(1, 1);
        }
    }
}");

            Assert.AreEqual(true, UsingStaticWalker.TryGet(tree, new QualifiedType("NUnit.Framework.Assert"), out var directive));
            Assert.AreEqual("using static NUnit.Framework.Assert;", directive.ToString());
        }