Skip to content

Commit 2003145

Browse files
committed
Test GetMethod when generic. #92
1 parent 1a876a8 commit 2003145

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

ReflectionAnalyzers.Tests/REFL003MemberDoesNotExistTests/ValidCode.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,27 @@ public MethodInfo Bar<T>()
220220
AnalyzerAssert.Valid(Analyzer, ExpectedDiagnostic, code);
221221
}
222222

223+
[Test]
224+
public void GetGenericMethod()
225+
{
226+
var code = @"
227+
namespace RoslynSandbox
228+
{
229+
using System.Reflection;
230+
231+
public class Foo
232+
{
233+
public Foo()
234+
{
235+
_ = typeof(Foo).GetMethod(nameof(Foo.Id), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
236+
}
237+
238+
public T Id<T>(T value) => value;
239+
}
240+
}";
241+
AnalyzerAssert.Valid(Analyzer, ExpectedDiagnostic, code);
242+
}
243+
223244
[TestCase("get_Bar")]
224245
[TestCase("set_Bar")]
225246
public void GetPropertyMethods(string name)

ValidCode/GenericMember.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace ValidCode
2+
{
3+
using System.Reflection;
4+
5+
public class GenericMember
6+
{
7+
public GenericMember()
8+
{
9+
_ = typeof(GenericMember).GetMethod(nameof(GenericMember.Id), BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
10+
}
11+
12+
public T Id<T>(T value) => value;
13+
}
14+
}

0 commit comments

Comments
 (0)