public static void NoMatch(string call)
            {
                var code = @"
namespace N
{
    using System;
    using System.Collections.Generic;
    using System.Reflection;

    public class C
    {
        public object Get() => typeof(Array).GetMethod(nameof(Array.CreateInstance), BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly, null, new[] { typeof(Type), typeof(int) }, null);
    }
}".AssertReplace("typeof(Array).GetMethod(nameof(Array.CreateInstance), BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly, null, new[] { typeof(Type), typeof(int) }, null)", call);

                var syntaxTree    = CSharpSyntaxTree.ParseText(code);
                var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
                var semanticModel = compilation.GetSemanticModel(syntaxTree);
                var invocation    = syntaxTree.FindInvocation("GetMethod");

                Assert.AreEqual(true, GetX.TryMatchGetMethod(invocation, semanticModel, CancellationToken.None, out var reflectedMember, out _, out _, out _));
                Assert.AreEqual(FilterMatch.WrongTypes, reflectedMember.Match);
            }
예제 #2
0
        public void GetMethodWrongFlagsWhenNotVisible()
        {
            var code          = @"
namespace RoslynSandbox
{
    using System;
    using System.Reflection;
    using System.Windows.Forms;

    class C
    {
        public object Get => typeof(Control).GetMethod(nameof(Control.CreateControl), BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(bool) }, null);
    }
}";
            var syntaxTree    = CSharpSyntaxTree.ParseText(code);
            var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
            var semanticModel = compilation.GetSemanticModel(syntaxTree);
            var invocation    = syntaxTree.FindInvocation("GetMethod");
            var context       = new SyntaxNodeAnalysisContext(invocation, null, semanticModel, null, null, null, CancellationToken.None);

            Assert.AreEqual(true, GetX.TryMatchGetMethod(invocation, context, out var reflectedMember, out _, out _, out _));
            Assert.AreEqual(FilterMatch.PotentiallyInvisible, reflectedMember.Match);
        }
            public static void Success(string call, string expected)
            {
                var code = @"
namespace N
{
    using System;
    using System.Collections.Generic;
    using System.Reflection;

    public class C
    {
        public object Get() => typeof(Array).GetMethod(nameof(Array.CreateInstance), new[] { typeof(Type), typeof(int) });
    }
}".AssertReplace("typeof(Array).GetMethod(nameof(Array.CreateInstance), new[] { typeof(Type), typeof(int) })", call);

                var syntaxTree    = CSharpSyntaxTree.ParseText(code);
                var compilation   = CSharpCompilation.Create("test", new[] { syntaxTree }, MetadataReferences.FromAttributes());
                var semanticModel = compilation.GetSemanticModel(syntaxTree);
                var invocation    = syntaxTree.FindInvocation("GetMethod");

                Assert.AreEqual(true, GetX.TryMatchGetMethod(invocation, semanticModel, CancellationToken.None, out var reflectedMember, out _, out _, out _));
                Assert.AreEqual(FilterMatch.Single, reflectedMember.Match);
                Assert.AreEqual(expected, reflectedMember.Symbol.ToDisplayString());
            }
예제 #4
0
 return(new Vector2(GetX(delta), GetY(delta)));